我正在嘗試使用 selenium 在網站內進行簡單的拖放操作,但是它不起作用,我不知道為什么。
網站:( https://app.orcatec.com/matrix )
我的代碼:
driver = webdriver.Firefox()
driver.get("https://app.orcatec.com/login")
time.sleep(2)
email = driver.find_element_by_id("login-email")
email.send_keys("xxxxxxx")
passw = driver.find_element_by_id("login-password")
passw.send_keys("xxxxxxxx")
login = driver.find_element_by_class_name("btn-primary")
login.click()
time.sleep(6)
那就是登錄
要拖放:
app_square = driver.find_element_by_xpath("/html/body/div[1]/main/div[1]/div[4]/div/div/div/div/div/div/div[2]/div[2]/div[2]/div[2]/div[1]/div/div/span/div[2]")
action = webdriver.common.action_chains.ActionChains(driver)
empty_square = driver.find_element_by_xpath("/html/body/div[1]/main/div[1]/div[4]/div/div/div/div/div/div/div[2]/div[1]/div[2]/div/div[2]/div[2]/div[1]/div[3]")
time.sleep(1)
action.move_to_element(app_square).pause(1).click_and_hold().move_to_element(empty_square).context_click().perform()
請讓我知道我做錯了什么。我還嘗試了其他各種使用 selenium 進行拖放的方法,例如 drag_and_drop 方法。
uj5u.com熱心網友回復:
使用 python 的 pyautogui 庫解決了這個問題。
代碼:
pyautogui.moveTo(2485, 373)
pyautogui.drag(-330, 80)
pyautogui.moveTo(2456, 458)
pyautogui.moveTo(2156, 458)
pyautogui.click()
uj5u.com熱心網友回復:
一個基本的方法是有 ActionChain drag_and_drop
ActionChains(driver).drag_and_drop(app_square, empty_square).pause(5).perform()
在這里閱讀更多
drag_and_drop(source, target)
Holds down the left mouse button on the source element,
then moves to the target element and releases the mouse button.
Args:
source: The element to mouse down.
target: The element to mouse up.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/318549.html
下一篇:關于htmlimgsrc
