通过xpath找到元素'没有这样的元素'错误

时间:2014-11-20 19:23:29

标签: xpath

有人可以告诉我为什么我无法访问"选择" XPath的?我得到"没有这样的元素存在"错误。网站链接为:https://www2.fdic.gov/sdi/main3.asp?cert=26486&repdte=MostCurrent。我使用的是selenium webdriver。

select=driver.find_element_by_xpath('/html/body/form/table[2]/tbody/tr/td[2]/table/tbody/tr/td/select')

2 个答案:

答案 0 :(得分:0)

尝试

select=driver.findElement(By.xpath('//form/table[2]/tbody/tr/td[2]/table/tbody/tr/td/select'))

在xpath的开头你使用'//'而不需要'html / body'

答案 1 :(得分:0)

我同意上面的@Marc B. select元素位于框架内,因此除非您切换到框架,否则您的代码将无效。

1 - 首先,使用以下代码切换到相框(有多种方式,这是其中之一):

   driver.switch_to_frame("content") //Found that the select tag is under frame with name "content"

2 - 然后,使用您的代码或下面的代码选择元素

select=driver.find_element_by_xpath('//select[@name='selColumnType2']')

3 - 完成框架任务后,使用以下代码切换回主窗口,然后继续:

driver.switch_to_default_content()
相关问题