Selenium – mouse operation

Foreplay

When we are doing automation, we sometimes use some mouse operations, such as double-clicking, mouse hovering and other operations. Selenium provides the ActionChains method for us to operate< /p>

Double click

from selenium import webdriver

from selenium.webdriver.common.action_chains import< span style="color: #000000;"> ActionChains
from time import sleep

driver
= webdriver.Chrome()
driver.get(
'http://www.baidu.com ')
driver.maximize_window()
driver.find_element_by_css_selector(
'#kw').send_keys('python span>')
sleep(
2)

# Assign the located search box to the variable
choose = driver.find_element_by_css_selector('#kw')

# Double click with the mouse
ActionChains(driver).double_click(choose).perform()

sleep(
2)

driver.quit()

right mouse button

from selenium import webdriver

from selenium.webdriver.common.action_chains import< span style="color: #000000;"> ActionChains
from time import sleep

driver
= webdriver.Chrome()
driver.get(
'http://www.baidu.com ')
driver.maximize_window()
driver.find_element_by_css_selector(
'#kw').send_keys('python span>')
sleep(
2)

# Assign the located search box to the variable
choose = driver.find_element_by_css_selector('#kw')

# Double click with the mouse
ActionChains(driver).double_click(choose).perform()

sleep(
2)
# Right mouse button
ActionChains(driver).context_click(choose).perform()

sleep(
2)
driver.quit()

Mouse hover

from selenium import webdriver

from selenium.webdriver.common.action_chains import< span style="color: #000000;"> ActionChains
from time import sleep

driver
= webdriver.Chrome()
driver.get(
'http://www.baidu.com ')
driver.maximize_window()
driver.find_element_by_css_selector(
'#kw').send_keys('python span>')
sleep(
2)

# locate class=pf and assign it to the variable move
move = driver.find_element_by_css_selector('.pf')

# mouse hover
ActionChains(driver).move_to_element(move).perform()

sleep(
2)
driver.quit()

from selenium < span style="color: #0000ff;">import webdriver

from selenium.webdriver.common.action_chains import< span style="color: #000000;"> ActionChains
from time import sleep

driver
= webdriver.Chrome()
driver.get(
'http://www.baidu.com ')
driver.maximize_window()
driver.find_element_by_css_selector(
'#kw').send_keys('python span>')
sleep(
2)

# Assign the located search box to the variable
choose = driver.find_element_by_css_selector('#kw')

# Double click with the mouse
ActionChains(driver).double_click(choose).perform()

sleep(
2)

driver.quit()

from selenium import webdriver

from selenium.webdriver.common.action_chains import< span style="color: #000000;"> ActionChains
from time import sleep

driver
= webdriver.Chrome()
driver.get(
'http://www.baidu.com ')
driver.maximize_window()
driver.find_element_by_css_selector(
'#kw').send_keys('python span>')
sleep(
2)

# Assign the located search box to the variable
choose = driver.find_element_by_css_selector('#kw')

# Double click with the mouse
ActionChains(driver).double_click(choose).perform()

sleep(
2)
# Right mouse button
ActionChains(driver).context_click(choose).perform()

sleep(
2)
driver.quit()

from selenium import webdriver

from selenium.webdriver.common.action_chains import< span style="color: #000000;"> ActionChains
from time import sleep

driver
= webdriver.Chrome()
driver.get(
'http://www.baidu.com ')
driver.maximize_window()
driver.find_element_by_css_selector(
'#kw').send_keys('python span>')
sleep(
2)

# locate class=pf and assign it to the variable move
move = driver.find_element_by_css_selector('.pf')

# mouse hover
ActionChains(driver).move_to_element(move).perform()

sleep(
2)
driver.quit()

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2224 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.