-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathselenium_ActionChains.py
More file actions
57 lines (42 loc) · 1.75 KB
/
Copy pathselenium_ActionChains.py
File metadata and controls
57 lines (42 loc) · 1.75 KB
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
56
57
import os
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
path = "C:\Program Files\chromedriver.exe"
driver = webdriver.Chrome(path)
driver.get("https:// ... ")
driver.implicitly_wait(5) # waiting a 5 sec for loading a web_page
some_elem = driver.find_element_by_id("id_name")
some_elem_count = driver.find_element_by_id("id_name")
actions = ActionChains(driver)
actions.click(some_elem)
for i in range(1000): # 1000 times
actions.perform()
driver.quit()
# or
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
path = "C:\\chromedriver.exe"
driver = webdriver.Chrome(path)
driver.get("http://www ... ")
wait = WebDriverWait(driver, 40)
driver.find_element_by_css_selector("span .... ").click()
wait.until(EC.element_to_be_clickable((By.XPATH, " ... "))).click()
element = driver.find_element_by_link_text('Some_text')
actionChains = ActionChains(driver)
actionChains.move_to_element(element).perform()
wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "Some_name"))).click()
# or , ActionChains can be used in a chain
menu = driver.find_element_by_css_selector("")
submenu = driver.find_element_by_css_selector("")
ActionChains(driver).move_to_element(menu).click(submenu).perform()
# or , actions can be queued up one by one
menu = driver.find_element_by_css_selector("")
submenu = driver.find_element_by_css_selector("")
actions = ActionChains(driver)
actions.move_to_element(menu)
actions.click(submenu)
actions.perform()