【问题标题】:selenium python element not interactable error硒python元素不可交互错误
【发布时间】:2020-04-16 06:16:55
【问题描述】:

我制作了自动注册的代码,但它不起作用 这是我要点击的目标

<div id="mainframe.childframe.form.div_main.form.div_work.form.chk_pricheckAll" class="CheckBox" tabindex="-1" style="left: 878px; top: 669px; width: 89px; height: 28px;" role="checkbox" aria-label="전체동의 " aria-description="" aria-checked="true" status="focused" userstatus="selected" aria-selected="true"><div id="mainframe.childframe.form.div_main.form.div_work.form.chk_pricheckAll:icontext" class="nexacontentsbox" style="left: 0px; top: 0px; width: 87px; height: 26px;"><img class="nexaiconitem" src="./_resource_/_theme_/esky_pc/images/btn_WF_CheS.png"><div class="nexatextitem" style="padding:0px 0px 0px 6px;display:inline-block;">전체동의</div></div></div>

我试过这个代码


driver.find_element_by_xpath('//*[@id="mainframe.childframe.form.div_main.form.div_work.form.chk_pricheckAll:icontext"]').click()

但它一直给我一个错误,我也试过这个

driver.find_element_by_xpath("//form[@class='mainframe.childframe.form.div_main.form.div_work.form.chk_pricheckAll:icontext']]").send_keys(Keys.ENTER)

它也没有工作 我试着用这样的脚本来做

element = driver.find_element_by_xpath("//form[@class='mainframe.childframe.form.div_main.form.div_work.form.chk_pricheckAll:icontext']]")
driver.execute_script("arguments[0].click();", element)

它没有给我一个错误,但它仍然无法点击它 我该如何解决这个问题?

whole code of my program

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
import os

username = os.environ.get('USERNAME')
desktop = 'c:\\users\\' + username + '\\desktop\\'

driver = webdriver.Chrome(executable_path=desktop +"chromedriver.exe")
driver.get('https://www.ehaneul.go.kr:5443/esky_p/esky_index.jsp#MENU:M211002000')
sleep(3)
driver.find_element_by_xpath('//*[@id="mainframe.childframe.form.div_main.form.btn_M211000000"]').click()
browser = driver
sleep(2)
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
wait = WebDriverWait(driver, 3)
element =wait.until(EC.element_to_be_clickable((By.ID, "mainframe.childframe.form.div_main.form.div_work.form.chk_pricheckAll")))
ActionChains(driver).move_to_element(element).click().perform()

编辑 它通过简单的滚动解决。那么现在,我怎样才能自动滚动呢?

【问题讨论】:

  • 请附上工作代码 sn-p。需要“导入”行。

标签: python html python-3.x selenium selenium-webdriver


【解决方案1】:
wait = WebDriverWait(driver, 10)    
element =wait.until(EC.element_to_be_clickable((By.ID, "mainframe.childframe.form.div_main.form.div_work.form.chk_pricheckAll")))    
ActionChains(driver).move_to_element(element).click().perform()

注意:请在您的解决方案中添加以下导入

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains

我可以在页面上看到您的按钮:

【讨论】:

  • 它说驱动程序未定义
  • 其实我只是试过了,但它给出了这样的错误
  • Traceback(最近一次调用最后):文件“C:/Users/82103/Desktop/이하늘매크로.py”,第 22 行,在 元素 =wait.until(EC.element_to_be_clickable( (By.ID, "mainframe.childframe.form.div_main.form.div_work.form.chk_pricheckAll"))) 文件 "C:\Users\82103\PycharmProjects\untitled\venv\lib\site-packages\selenium\webdriver\ support\wait.py",第 80 行,直到 raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
  • 你能提供你的链接吗?我认为你的元素在 iframe 下,所以在处理你的元素之前尝试切换到 iframe
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-06
  • 1970-01-01
  • 2019-09-30
  • 1970-01-01
  • 1970-01-01
  • 2020-04-27
  • 1970-01-01
相关资源
最近更新 更多