webdriver python code example
Example 1: webdriverwait python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Firefox()
driver.get("http://somedomain/url_that_delays_loading")
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "myDynamicElement"))
)
finally:
driver.quit()
Example 2: how to start off a selenuim python
import selenium.webdriver as webdriver
driver = webdriver.Chrome()
Example 3: selenium webdriver python
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
Example 4: selenium webdriver tutorial python
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
dir = os.path.dirname(__file__)
chrome_driver_path = dir + "\chromedriver.exe"
driver = webdriver.Chrome(chrome_driver_path)
driver.implicitly_wait(30)
driver.maximize_window()
driver.get("http://www.google.com")
search_field = driver.find_element_by_name("q")
search_field.send_keys("Selenium WebDriver Interview questions")
search_field.submit()
lists= driver.find_elements_by_class_name("r")
print ("Found " + str(len(lists)) + " searches:")
i=0
for listitem in lists:
print (listitem.get_attribute("innerHTML"))
i=i+1
if(i>10):
break
driver.quit()