ActionChains 的妙用

迷龙發表於2020-10-25

from time import sleep
import pyautogui
from selenium import webdriver
from selenium.webdriver import ActionChains


def test2():
driver = webdriver.Chrome(executable_path='E:\my_selenium_project\driver\chromedriver.exe')
driver.get('http://www.jpress.io/user/register')
driver.maximize_window()

ele = driver.find_element_by_id('agree')

ActionChains(driver).move_to_element(ele).click().perform()
sleep(30)
#老師的程式碼在自己機器上無法成功定位,改用ActionChains成功解決
# rect = ele.rect
# pyautogui.click(rect['x'] + 10, rect['y'] + 130)
# sleep(30)


if __name__ == '__main__':
test2()

相關文章