【发布时间】:2020-02-25 13:08:04
【问题描述】:
我正在尝试在字段中写入“eureka”,而 Selenium 总是触发相同的错误:NoSuchElementException
这是我试图从中获取数据的字段:
<input type="text" class="standardTextField" id="rulesFilternameValue" name="rulesFilternameValue" onclick="if(typeof event !== 'undefined' && event != null) {event.cancelBubble=true;}if(typeof event !== 'undefined' && event != null) {event.cancelBubble=true;}" onkeypress="if (event.keyCode === 13){event.preventDefault();handleFilterRequest('rulelist', 'FILTER')}">
我已经尝试过使用 find_element_by_id、find_element_by_class、find_element_by_xpath 什么都没有。
整个事情都在 iFrame 中:
<iframe id="mainwindow" name="mainwindow" style="top: 54px; height: 849px;"
src="/h2/welcomeAction.do?misc=1582634309181" frameborder="0"></iframe>
但事件 find_element_by_id('mainwindow') 失败
【问题讨论】:
-
这能回答你的问题吗? Select iframe using Python + Selenium
-
不幸的是:browser.switch_to.frame(browser.find_element_by_tag_name("iframe")) -> NoSuchElementException:消息:无法定位元素:iframe
-
您必须将您的 selenium 驱动程序重定向到正确的框架。你说它是一个 iframe,这意味着 selenium 不知道它。因此,在页面上找到驱动程序可用的不同框架并选择 iframe。然后做你的
find_element -
疑问:当我做 switch_to.frame(browser.find_element_by_tag_name("iframe")) 我也得到一个 NoSuchElementException
-
我错了,你们是对的人。很抱歉,非常感谢您的帮助:-)