Selenium教程

Selenium Webdriver定位策略-(通过XPath-使用And)

在本节中,您将学习如何通过XPath-使用And来定位特定的Web元素。
让我们考虑一个示例,在该示例中,我们将尝试使用XPath-使用And查找Google搜索引擎的文本框。
请按照下面提供的步骤来找到Google提供的文本框。 Google搜索引擎的首页。
打开URL: https://www.google.co.in/在您的Firefox浏览器中 右键单击示例网页上的"文本框",然后选择"检查元素" 定位策略-通过XPath-使用And 它将启动一个窗口,其中包含文本框开发中涉及的所有特定代码。 定位策略-通过XPath-使用And 记下它的id和Class属性。 定位策略-通过XPath-使用And
语法通过XPath定位元素-使用和可以写为:
//<HTML tag>[@attribute_name1='attribute_value1' and @attribute_name2='attribute_value2]
//*[@attribute_name1='attribute_value1' and @attribute_name2='attribute_value2]
使用XPath,而且,我们可以将Java代码以及动态XPath位置编写为:
findElement(By.xpath("//*[@id='lst-ib' and @class='gsfi lst-d-f']"));

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4