简体   繁体   English

python selenium chromedriver xpath“没有这样的元素”

[英]python selenium chromedriver xpath “no such element”

I'm running Python 3.6 on an iMac (OS: Sierra). 我在iMac(操作系统:Sierra)上运行Python 3.6。 I use ChromeDriver 2.33 and the latest version of the Selenium package (from PIPY). 我使用的是ChromeDriver 2.33和最新版本的Selenium软件包(来自PIPY)。 I'm trying to access (using find_element_by_xpath ) the column elements of a table row as shown below: 我正在尝试访问(使用find_element_by_xpath )表行的列元素,如下所示:

HTML Code HTML代码

I can access the first three cells (TH tags) embedded inside the row (TR tag). 我可以访问行(TR标签)中嵌入的前三个单元格(TH标签)。 When I get to the 4th cell (TH tag) the chrome driver reports (via python) 'No such element'. 当我到达第四个单元格(TH标签)时,chrome驱动程序报告(通过python)“没有这样的元素”。

I'm waiting 10s of seconds after loading the page before trying to access the element (also, I can excess cell 1-3 for this row) so this is obviously not a timing issue. 我在加载页面后等待10秒钟,然后尝试访问元素(此外,我可以在此行中增加单元格1-3),因此这显然不是时间问题。

The web element (cell #4) is visible in the web browser. Web元素(单元格4)在Web浏览器中可见。 Also, I used the web element search function in chrome developer to check the xpath (and it checks out just fine). 另外,我在chrome开发人员中使用了Web元素搜索功能来检查xpath(并且可以很好地进行检查)。 Obviously, the issue is not that the element isn't visible. 显然,问题不是该元素不可见。

I wonder what the issue is? 我想知道问题是什么? Or at least I'd like some recommendation on how to debug this? 或者至少我想要一些有关如何调试它的建议?


In response to comments: I use the following python call 回应评论:我使用以下python调用

CHROMEDRIVER.find_element_by_xpath("//*[@id="mainContent_ugReservationGrid_tableGridParent"]/div 1 /table/thead/tr[3]/th[INDEX]")' where 'INDEX' is my loop-variable.. 1-3 works fine but when the loop variable gets to 4 I get the exception ' No Such Element '. CHROMEDRIVER.find_element_by_xpath(“ // * [@ id =” mainContent_ugReservationGrid_tableGridParent“] / div 1 / table / thead / tr [3] / th [INDEX]”)'其中'INDEX'是我的循环变量。1-3工作正常,但当循环变量达到4时,出现异常' No Such Element '。


Replaced Chrome with Firefox & geckodriver: It seems to be an issue with the Chrome interface. 用Firefox和geckodriver取代了Chrome:Chrome界面似乎有问题。 Firefox works as expected w/o any other changes. Firefox可以正常工作,没有其他任何更改。

If you are not experiencing timing issues while referencing the other table cells, it would be worthwhile to further validate the xpath you're using for the element which you can never seem to reach. 如果您在引用其他表单元格时没有遇到时序问题,那么有必要进一步验证您正在使用的xpath来处理似乎无法到达的元素。

Even though I tend to run all of my automation primarily through Chrome, I will still occasionally use Firefox with the FirePath plugin for picking/validating locators on a page. 即使我倾向于主要通过Chrome运行所有自动化程序,我还是偶尔会使用带有FirePath插件的Firefox来选择/验证页面上的定位器。 This plugin is particularly useful in that it will yield all matches for a given locator. 该插件特别有用,因为它将产生给定定位器的所有匹配项。 One reason why automation might fail (or at least behave unpredictably) is that a locator might have more than one match. 自动化可能失败(或至少行为无法预测)的原因之一是定位器可能具有多个匹配项。

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

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