python selenium usage code example
Example 1: 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()
Example 2: python selenium setup
from selenium import webdriver
import unittest
class example(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome("C:\Program Files (x86)\chromedriver.exe")
cls.driver.maximize_window()
def test_login(self):
self.driver.get("https://eu-uat2.weissr-cloud.com")
@classmethod
def tearDownClass(cls):
cls.driver.quit()
print("Test Completed")
if __name__ == '__main__':
unittest.main()