简体   繁体   English

selenium python 元素不可交互错误

[英]selenium python element not interactable error

i made code to register automatically but it's not working this is my target to click我制作了自动注册的代码,但它不起作用这是我点击的目标

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

i tried this code我试过这段代码


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

but it keep gives me an error and i also tried this但它一直给我一个错误,我也试过这个

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

and it didn't work either i tried to do it with script like this它也不起作用我试图用这样的脚本来做

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)

and it didn't give me an error but it still can't click it how can i fix this?它没有给我一个错误,但它仍然无法点击它我该如何解决这个问题?

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

edit it solved with simple scroll.编辑它用简单的滚动解决。 so now, how can i scroll automatically?所以现在,我怎样才能自动滚动?

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

Note: please add below imports to your solution注意:请将以下导入添加到您的解决方案中

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

I can see your button on a page:我可以在页面上看到您的按钮:

在此处输入图像描述

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

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