简体   繁体   English

硒在iFrame标签后找不到元素element

[英]Selenium not finding elements elements after an iFrame tag

I'm trying to find a search box in some HTML and selenium won't find it. 我正在尝试在某些HTML中找到搜索框,而硒将找不到它。

I've tried the following. 我已经尝试了以下方法。

driver.find_element_by_id
driver.find_element_by_class_name
driver.find_element_by_xpath
driver.find_element_by_css_selector

nothing has worked so far. 到目前为止,没有任何工作。

I've also gone line by line through the HTML and found the point where it stops picking up the elements, and in between the last one it can find and the first one it can't find is a text string as follows. 我还逐行浏览了HTML,发现它停止拾取元素的位置,在它可以找到的最后一个元素和找不到的第一个元素之间是一个文本字符串,如下所示。 (<> removed because otherwise I can't post it) (<>已删除,因为否则我无法发布它)

iframe id="iframeCenter" src="url initialise=true" width="100%" 
onload="resizePortlet()" frameborder="0" height="894"
/iframe

#document

!-- tabbedFindMaintenanceLayout.jsp --
html class="dj_quirks ... "/html etc

The part that says src="URL has been shortened for security reasons, but it was just the url of the web page I have active 出于安全原因,说出src =“ URL的部分已被缩短,但这只是我已激活的网页的url

The search button is located further down inside this HTML tag but my driver can't get there. 搜索按钮位于此HTML标记内的更下方,但我的驱动程序无法到达那里。

Here is the html of the search box 这是搜索框的html

tr

td class="form_inputBoxTitle"><input type="text" name="search" size="20" 
value="" id="form_search"/td

input type="text" name="search" size="20" value="" id="form_search"

/tr

Now for my code :/ 现在输入我的代码:/

finding search box 寻找搜寻框

search_box = driver.find_element_by_class_name('form_inputBoxTitle')
search_box.send_keys(phc)

finding iframe 寻找iframe

iFrame = driver.find_element_by_id('iframeCenter')

finding html class 查找html类

dj = driver.find_element_by_id('dj_quirks ')

iFrame finds the correct html tag as I would expect it to. iFrame会找到我期望的正确的html标签。 search_box and dj both return the following error message. search_box和dj都返回以下错误消息。

search_box = driver.find_element_by_class_name('form_inputBoxTitle')
  File "C:\Users\webdriver.py", line 564, in find_element_by_class_name
    return self.find_element(by=By.CLASS_NAME, value=name)
  File "C:\Users\webdriver.py", line 978, in find_element
    'value': value})['value']
  File "C:\Users\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such 
element: Unable to locate element: {"method":"css 
selector","selector":".form_inputBoxTitle"}
  (Session info: chrome=76.0.3809.132)

What is the issue here? 这是什么问题?

Try this: 尝试这个:

search_box = driver.find_element_by_id("form_search")
search_box.send_keys("foo")

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

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