Selenium在iFrame标记后找不到元素

2024-04-30 06:20:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在一些HTML中找到一个搜索框,但selenium找不到它。你知道吗

我试过以下方法。你知道吗

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

到目前为止还没有任何进展。你知道吗

我还逐行浏览了HTML,找到了它停止提取元素的点,在它能找到的最后一个元素和找不到的第一个元素之间有一个文本字符串,如下所示。 (<;>;已删除,否则无法发布)

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

表示src=“URL”的部分由于安全原因被缩短,但它只是我激活的网页的URL

搜索按钮位于这个HTML标签的下方,但是我的驱动程序无法到达那里。你知道吗

这是搜索框的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

现在输入我的代码:/

查找搜索框

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

查找iframe

iFrame = driver.find_element_by_id('iframeCenter')

查找html类

dj = driver.find_element_by_id('dj_quirks ')

iFrame找到了正确的html标记。 search\u 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)

这里有什么问题?你知道吗


Tags: nameformboxidsearchbyvaluehtml