forked from qxf2/selenium-beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08_Hover.py
57 lines (42 loc) · 1.54 KB
/
08_Hover.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Learn to hover over elements using Selenium
DISCLAIMER: This code is aimed at Selenium BEGINNERS
For more advanced tutorials and to learn how Qxf2 writes GUI automation, please visit our:
a) Our GUI automation guides: http://qxf2.com/gui-automation-diy
b) Other GitHub repos: https://github.com/qxf2
AUTHOR: Avinash Shetty
Contact: [email protected]
SCOPE:
1) Launch Firefox driver
2) Navigate to Qxf2 Tutorial page
3) Click on Menu icon
4) Hover over Resource and GUI automation and click on GUI automation link
5) Close the browser
"""
import time
from selenium import webdriver
#Notice this extra import statement!
from selenium.webdriver.common.action_chains import ActionChains
# Create an instance of Firefox WebDriver
driver = webdriver.Firefox()
# Maximize the browser window
driver.maximize_window()
# Navigate to Qxf2 Tutorial page
driver.get("http://qxf2.com/selenium-tutorial-main")
# Locate the Menu icon and click on it
menu = driver.find_element_by_xpath("//img[@src='./assets/img/menu.png']")
menu.click()
# Locate the Resource element to hover over
resource = driver.find_element_by_xpath("//a[text()='Resources']")
# KEY POINT: Use ActionChains to hover over elements
action = ActionChains(driver)
action.move_to_element(resource)
action.perform()
time.sleep(2) #Adding waits to make the example more visual
# Click the GUI automation link
gui_automation = driver.find_element_by_xpath("//a[text()='GUI automation']")
gui_automation.click()
# Wait for 3 seconds for the page to load
time.sleep(3)
# Close the browser
driver.close()