硒重复元素标记为

硒重复元素标记为

本文介绍了硒重复元素标记为== $ 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-$ 4

$0$1$2$3$4是对或最后五个在个人档案"面板中选择的JavaScript堆对象. $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.

在您的用例中,您已通过元素"面板检查了按钮.因此,在控制台抽屉中,$0已被评估并显示与以下元素相同的元素:

In your usecase, you have inspected the button through the Elements panel. So in the Console drawer, $0 has been evaluated and displays the same element as:

有关您的用例的更多信息将有助于我们以更好的方式回答您的问题.但是, HTML DOM 中的每个元素都可以使用 css-selectors 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 02:02