带有硒的 Python:无法定位真正存在的元素 [英] Python with selenium: unable to locate element which really exist
问题描述
我一直在尝试填充输入:
I've been trying fill input:
<input id="PASSFIELD1" class="logField" type="password" onkeyup="next(this, event);" maxlength="1" autocomplete="off" name="PASSFIELD1"></input>
要做到这一点,我必须找到这个元素.
To do this, I have to find this element.
我尝试了以下内容:
pass1=driver.find_element_by_name("PASSFIELD1")
pass1=driver.find_element_by_id("PASSFIELD1")
pass1= driver.find_element_by_xpath("/html/body/div[4]/div/div/div[2]/div/form/div[3]/table/tbody/tr[3]/td[2]/div/input[1]")
(来自萤火虫的路径)
甚至等待 100 秒
Even wait 100 seconds for it
self.wait.until(EC.visibility_of_element_located((By.XPATH,"/html/body/div[4]/div/div/div[2]/div/form/div[3]/表/tbody/tr[3]/td[2]/div/input[1]")))self.assertTrue(self.driver.find_element_by_xpath("/html/body/div[4]/div/div/div[2]/div/form/div[3]/table/tbody/tr[3]/td[2]/div/input[1]"))
我总是得到:
selenium.common.exceptions.NoSuchElementException:消息:'无法定位元素:(...)
selenium.common.exceptions.NoSuchElementException: Message: 'Unable to locate element: (...)
你知道我做错了什么吗?
Do you know what I am doing wrong?
推荐答案
问题是你的 input
标签在 iframe
内,你需要 首先切换到:
The problem is that your input
tag is inside an iframe
, you need to switch to it first:
frame = driver.find_element_by_xpath('//frame[@name="main"]')
driver.switch_to.frame(frame)
pass1 = driver.find_element_by_id("PASSFIELD1")
这篇关于带有硒的 Python:无法定位真正存在的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!