1from selenium import webdriver
2
3chrome_driver_path = 'C:\Development\chromedriver.exe'
4driver = webdriver.Chrome(executable_path=chrome_driver_path)
5
6driver.get('https://www.python.org')
7
8name = driver.find_element_by_name('q')
9print(name.get_attribute('placeholder'))
10
11python_logo = driver.find_element_by_class_name('python-logo')
12print(python_logo.size)
13
14documentation_link = driver.find_element_by_css_selector('.documentation-widget a')
15print(documentation_link.text)
16
17anchor_xpath = driver.find_element_by_xpath('//*[@id="search"]/div[2]/div[6]/div[1]/div/div'))
18print(anchor_xpath.text)
19# you can get xpath by right click and inspect > right click on element >
20# >> copy >>> XPath
21
22# you can also search by class selector
23# id_selector = driver.find_element_by_id('#id')
24
25driver.quit()
1#In Python
2
3#Let's say that we want to locate the h1 tag in this HTML:
4#<html>
5# <head>
6# ... some stuff
7# </head>
8# <body>
9# <h1 class="someclass" id="greatID">Super title</h1>
10# </body>
11#</html>
12
13h1 = driver.find_element_by_name('h1')
14h1 = driver.find_element_by_class_name('someclass')
15h1 = driver.find_element_by_xpath('//h1')
16h1 = driver.find_element_by_id('greatID')
17