python-selenium-paste, delete, copy and hover

Posted Jun 16, 20201 min read

from selenium import webdriver

from selenium.webdriver.common.keys import Keys
import time

Visit Google Chrome

driver=webdriver.Chrome()

address

driver.get("")

Maximum window

driver.maximize_window()

time.sleep(1)

Enter text

ele=driver.find_element_by_xpath('//*[@id="kw"]')
ele.send_keys("League of Legends")

ele.send_keys(Keys.BACKSPACE)

time.sleep(1)

select all

ele.send_keys(Keys.CONTROL,'a')
time.sleep(1)

Cut

ele.send_keys(Keys.CONTROL,'x')
time.sleep(1)

Paste

ele.send_keys(Keys.CONTROL,'v')

Hover

from selenium import webdriver

Hover pack

from selenium.webdriver import ActionChains

import time
# Create browser
driver = webdriver.Chrome()

Adjust browser size

driver.maximize_window()

# visit link
driver.get(" https://study.163.com/" )
driver.find_element_by_xpath('//*[@id="ux-modal"]/div[3]/span').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="j-pclose"]').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="ux-modal"]/div[1]/a').click()
time.sleep(1)

Hover usage

ActionChains(driver).move_to_element(driver.find_element_by_xpath('//span[@class="arrow down ux-icon-caret-down"]')).perform()
# time.sleep(1)
ActionChains(driver).move_to_element(driver.find_element_by_xpath('(//a)[@title="Life Interest"][2]')).perform()
# time.sleep(1)
driver.find_element_by_xpath('(//a)[@title=" DIY"][2]').click()
# Save snapshot
driver.save_screenshot("1.png")