1from selenium import webdriver
2from selenium.webdriver.common.keys import Keys
3
4driver = webdriver.Firefox()
5driver.get("http://www.python.org")
6assert "Python" in driver.title
7elem = driver.find_element_by_name("q")
8elem.clear()
9elem.send_keys("pycon")
10elem.send_keys(Keys.RETURN)
11assert "No results found." not in driver.page_source
12driver.close()
13
1import os
2from selenium import webdriver
3from selenium.webdriver.common.keys import Keys
4
5# get the path of ChromeDriverServer
6dir = os.path.dirname(__file__)
7chrome_driver_path = dir + "\chromedriver.exe"
8
9# create a new Chrome session
10driver = webdriver.Chrome(chrome_driver_path)
11driver.implicitly_wait(30)
12driver.maximize_window()
13
14# Navigate to the application home page
15driver.get("http://www.google.com")
16
17# get the search textbox
18search_field = driver.find_element_by_name("q")
19
20# enter search keyword and submit
21search_field.send_keys("Selenium WebDriver Interview questions")
22search_field.submit()
23
24# get the list of elements which are displayed after the search
25# currently on result page using find_elements_by_class_name method
26lists= driver.find_elements_by_class_name("r")
27
28# get the number of elements found
29print ("Found " + str(len(lists)) + " searches:")
30
31# iterate through each element and print the text that is
32# name of the search
33
34i=0
35for listitem in lists:
36 print (listitem.get_attribute("innerHTML"))
37 i=i+1
38 if(i>10):
39 break
40
41# close the browser window
42driver.quit()
43
1from selenium import webdriver
2import unittest
3
4class example(unittest.TestCase):
5
6 @classmethod
7 def setUpClass(cls):
8
9 cls.driver = webdriver.Chrome("C:\Program Files (x86)\chromedriver.exe")
10 cls.driver.maximize_window()
11
12 def test_login(self):
13
14 self.driver.get("https://eu-uat2.weissr-cloud.com")
15
16 @classmethod
17 def tearDownClass(cls):
18
19 cls.driver.quit()
20 print("Test Completed")
21
22if __name__ == '__main__':
23 unittest.main()
1from selenium import webdriver
2from selenium.webdriver.common.keys import Keys
3
4driver = webdriver.Firefox()
5driver.get("http://www.python.org")
6assert "Python" in driver.title
7elem = driver.find_element_by_name("q")
8elem.clear()
9elem.send_keys("pycon")
10elem.send_keys(Keys.RETURN)
11assert "No results found." not in driver.page_source
12driver.close()
1import timefrom selenium import webdriverdriver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.driver.get('http://www.google.com/');time.sleep(5) # Let the user actually see something!search_box = driver.find_element_by_name('q')search_box.send_keys('ChromeDriver')search_box.submit()time.sleep(5) # Let the user actually see something!driver.quit()