简体   繁体   English

当机器人尝试单击协议按钮时,python selenium 元素不可交互

[英]python selenium element not interactable when bot tries to click agreement button

<input id="agreement-input-mobile" class="agreement-input" type="checkbox" name="agreement" aria-describedby="agreement-content">

im trying to automate a certain task but it needs to click an agreement button but every time I try to select it I get this error我试图自动化某个任务,但它需要单击一个协议按钮,但每次我尝试选择它时,我都会收到此错误

 selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=87.0.4280.67)

here's what my line of code looks like这是我的代码行的样子

driver.find_element_by_name('agreement').click()

I wouldn't recommend to find elements by name.我不建议按名称查找元素。 Use ID or xpath.使用 ID 或 xpath。 So change driver.find_element_by_name('agreement').click() to driver.find_element_by_id('agreement-input-mobile').click()所以将driver.find_element_by_name('agreement').click()改为driver.find_element_by_id('agreement-input-mobile').click()

Instead of .click() method, you can try another way like this:代替.click()方法,您可以尝试另一种方法,如下所示:

  1. Using ActionChains :使用动作ActionChains

     #following import from selenium.webdriver import ActionChains element = driver.find_element_by_id('agreement-input-mobile') action = ActionChains(driver) action.move_to_element(element).click(element).perform()
  2. Using .execute_script :使用.execute_script

     element = driver.find_element_by_id('agreement-input-mobile') driver.execute_script("arguments[0].click();", element)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM