硒python元素不可交互错误

时间:2020-04-16 06:16:55

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

我使代码自动注册,但无法正常工作 这是我要点击的目标

<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()

编辑 它通过简单的滚动解决了。所以现在,我如何自动滚动?

1 个答案:

答案 0 :(得分:0)

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

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

DataFrame.merge