硒重复元素标记为== $ 0 [英] Selenium Duplicate Elements marked with ==$0
问题描述
如何处理硒中的重复元素,其中重复元素带有==$0
标记?
How to handle duplicate elements in selenium, where duplicate elements comes marked with ==$0
?
转到www.google.com并搜索google搜索按钮,我已经尝试了迭代器并创建列表,但这是处理==$0
Go to www.google.com and search for google search button, I have tried iterator and creating list, but, is this correct way of handling ==$0
driver.findElements(By.xpath("//input[@aria-label='Google Search']"));
我要选择第二个元素.
推荐答案
. $0
返回最近选择的元素或JavaScript对象,$1
返回第二个最近选择的元素,依此类推.
$0 - $4
The $0
, $1
, $2
, $3
and $4
are the historical reference to the last five DOM elements inspected within the Elements panel of or the last five JavaScript heap objects selected in the Profiles panel. $0
returns the most recently selected element or JavaScript object, $1
returns the second most recently selected one, and so on.
在您的用例中,您已通过元素"面板检查了 Google搜索按钮.因此,在控制台抽屉中,$0
已被评估并显示与以下元素相同的元素:
In your usecase, you have inspected the Google Search button through the Elements panel. So in the Console drawer, $0
has been evaluated and displays the same element as:
有关您的用例的更多信息将有助于我们以更好的方式回答您的问题.但是, HTML DOM 中的每个元素都可以使用 xpath .
A bit more information about your usecase would have helped us to answer your question in a better way. However every element within the HTML DOM can be identified uniquely using either css-selectors or xpath.
如果您的用例是 Google搜索任何特定的术语/短语,则可以使用以下解决方案:
If your usecase is to Google Search any particular term/phrase, you can use the following solution:
WebElement searchField = driver.findElement(By.name("q"));
searchField.sendKeys("user3245610");
searchField.sendKeys("Keys.RETURN");
您可以在
查看全文
$0
, $1
, $2
, $3
and $4
are the historical reference to the last five DOM elements inspected within the Elements panel of or the last five JavaScript heap objects selected in the Profiles panel. $0
returns the most recently selected element or JavaScript object, $1
returns the second most recently selected one, and so on.$0
已被评估并显示与以下元素相同的元素:$0
has been evaluated and displays the same element as:WebElement searchField = driver.findElement(By.name("q"));
searchField.sendKeys("user3245610");
searchField.sendKeys("Keys.RETURN");
您可以在 查看全文