====== Python - Selenium ======
https://linuxhint.com/selenium-web-automation-python/
===== Installation =====
python3 -m pip install selenium
wget -N https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -P ~/
sudo dpkg -i --force-depends ~/google-chrome-stable_current_amd64.deb
https://sites.google.com/a/chromium.org/chromedriver/downloads
sudo cp ~/Downloads/chromedriver /usr/local/bin/
===== basics =====
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://google.com")
search_box = driver.find_element_by_name("q")
print(search_box)
search_button = driver.find_element_by_name("btnK")
search_button.click()
search_box.clear()
search_box.send_keys("test")
from selenium.webdriver.common.keys import Keys
search_box.send_keys(Keys.RETURN)
===== warten auf element =====
https://stackoverflow.com/a/59130336/15030988
===== itemliste =====
results=driver.find_elements(By.CSS_SELECTOR,"dt[class=ui-datalist-item]") #get multiple elements matching the selector
for i in results:
data=i.find_element_by_css_selector('div[id*=indexSearchResultForm] > span').text #search item below current element
===== einfache Klasse =====
class simplebrowser:
def __init__(self,driver):
self.driver = driver
self.wait = WebDriverWait(self.driver, 10)
def search(self,text):
print("searchstring: ",text)
resultlist=[]
try:
self.driver.get(SB_SEARCH_URL)
searchbox=self.wait.until(presence_of_element_located((By.CSS_SELECTOR, "input[id*=SearchBox]")))
searchbox.send_keys(text + Keys.RETURN)
...
resultlist.append(data)
except Exception as e:
print("error:",e.message)
finally:
return resultlist
===== Tabs =====
ungetested: https://stackoverflow.com/questions/28431765/open-web-in-new-tab-selenium-python
https://www.browserstack.com/guide/how-to-switch-tabs-in-selenium-python
https://www.lambdatest.com/blog/python-selenium-switch-tabs/