简体   繁体   English

使用复选框后如何获取更新的 DOM?

[英]How to get updated DOM after using checkboxes?

I know that the title of asking is quite vague.我知道询问的标题很模糊。 But let's check this page: https://www.cleaneye.go.kr/user/gongsiCompare.do但是让我们看看这个页面: https://www.cleaneye.go.kr/user/gongsiCompare.do

So this is one of public data page in Korea which has a data I need in my research.所以这是韩国的公共数据页面之一,其中包含我在研究中需要的数据。 As you can see, it has some checkbox in ul, and if you check one of the box in left one, the list of checkbox on its right would come up.如您所见,它在 ul 中有一些复选框,如果您选中左侧的其中一个框,则会出现其右侧的复选框列表。

So I made a code to check every combinations, and I'll show you the one which cause the problem.所以我编写了一个代码来检查每个组合,我会告诉你导致问题的那个。

from selenium import webdriver
driver = webdriver.Chrome(CHROMEDRIVER_LOCATION)
driver.get('https://www.cleaneye.go.kr/user/gongsiCompare.do')

in_type = driver.find_elements_by_xpath("//div[@id='divPcomp']/ul/li")
for in_t in in_type:
    in_t.find_element_by_xpath("./label/input").click()

    region_type = driver.find_elements_by_xpath("//div[@id='divSido']/ul/li")
    for r_t in region_type:
        r_t.find_element_by_xpath("./label/input").click()

The problem is, when the code execute问题是,当代码执行时

r_t.find_element_by_xpath("./label/input").click()

it gives ElementNotInteractableException error, maybe cuz DOM didn't revised after it clicked the checkbox in它给出了 ElementNotInteractableException 错误,也许是因为 DOM 在单击复选框后没有修改

in_t.find_element_by_xpath("./label/input").click()

So I've searched how to solve this problem, and most of answers were about using implicit/explicit wait.所以我搜索了如何解决这个问题,大多数答案都是关于使用隐式/显式等待。 Before I do that, I put time.wait(30) between click()s, and still it didn't work.在我这样做之前,我将 time.wait(30) 放在 click() 之间,但它仍然没有用。 So just waiting might not be the solution for this.因此,等待可能不是解决此问题的方法。

As you can see, if you refresh it, the whole page would be reset so... that is not the answer for this as well.如您所见,如果您刷新它,整个页面将被重置,所以......这也不是这个问题的答案。

Is there any great solution, or any walk-around it, please enlighten me.有没有什么好的解决方案,或者任何解决方法,请赐教。 Otherwise, I'll just use mouseclick and keyboard inputting 'tab' haha...否则,我将只使用鼠标单击和键盘输入“选项卡”哈哈...

Thanks for your attention to this problem!感谢您对这个问题的关注!

your locator is not unique, it finds element that is not visible on screen use:您的定位器不是唯一的,它会找到在屏幕使用中不可见的元素:

region_type = driver.find_elements_by_xpath("//div[@id='divSido']/ul/li[@class='rowon']")

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

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