本文介绍了Selenium WebDriver“find_element_by_xpath”在WebElement上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  elements = driver.find_elements_by_xpath(//一旦我有了元素,我知道那里的元素。[div class ='Display'])

是两个显示,我想能够使用第二个,并找到其中的特定元素,如下所示:

  title = elements [1] .find_element_by_xpath(// div [@ class ='Title'])

然而,它总是回复到使用第一个。我已经通过了它,它找到了显示的2个元素,所以我不知道我在做什么错。



任何帮助将非常感谢。

解决方案

我想你想这样:

<$ p $元素= [$ class ='Display'])
title = elements [1] .find_elements_by_xpath(.// div [@ class = 'Title'])


I'm trying to look up an element using the following line:

elements = driver.find_elements_by_xpath("//div[@class='Display']")

Once i have the elements, which I know there are two of "Display", i want to be able to use the second one and find a specific element inside it, like so:

title = elements[1].find_element_by_xpath("//div[@class='Title']")

However, it always reverts to using the first one. I've stepped through it, and it is finding 2 elements for "Display", so i'm not sure what I'm doing wrong.

Any help would be greatly appreciated.

解决方案

I think you want this:

elements = driver.find_elements_by_xpath("//div[@class='Display']")
title = elements[1].find_elements_by_xpath(".//div[@class='Title']")

这篇关于Selenium WebDriver“find_element_by_xpath”在WebElement上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 19:08