Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
selenium中用于单击元素的xpath_Selenium_Xpath - Fatal编程技术网

selenium中用于单击元素的xpath

selenium中用于单击元素的xpath,selenium,xpath,Selenium,Xpath,这是HTML代码,对于方框,请告诉我如何为方框中的任何元素找到正确的xpath。 该框包含元素列表,单击时元素从左框转移到右框,反之亦然 农业和矿业-农业和牧场 农业和矿业-捕鱼、狩猎和诱捕 Xpath可以是:- //select[@id='my-select-industry']/option[@value='2'] 在这种情况下,您可以使用 Select dropdown = new Select(driver.findElement(By.id("my-select-indust

这是HTML代码,对于方框,请告诉我如何为方框中的任何元素找到正确的xpath。 该框包含元素列表,单击时元素从左框转移到右框,反之亦然



农业和矿业-农业和牧场
农业和矿业-捕鱼、狩猎和诱捕

Xpath可以是:-

//select[@id='my-select-industry']/option[@value='2']
在这种情况下,您可以使用

Select dropdown = new Select(driver.findElement(By.id("my-select-industry")));
你可以选择“农业和采矿——捕鱼、狩猎和诱捕”这样的选项

dropdown.selectByVisibleText("Agriculture and Mining - Fishing, Hunting and Trapping ");

希望它能帮助您:)

List options=driver.findElements(By.xpath(“//option”);
您还可以使用相对xpath搜索“option”标记(从“已知”[以前找到的]元素向下搜索),但这需要您在“option”之前添加“.”点而不是双斜杠

e、 g

WebElement selectElement=driver.findElement(By.id(“我的选择行业”);
List options=selectElement.findElements(By.xpath(“./option”);

这里有一个类似的例子,说明您正在尝试做什么:

请展示您到目前为止尝试了什么
dropdown.selectByVisibleText("Agriculture and Mining - Fishing, Hunting and Trapping ");
dropdown.selectByIndex(2);
 dropdown.selectByValue("2");
List<WebElement> options = driver.findElements(By.xpath("//option"));
WebElement selectElement = driver.findElement(By.id("my-select-industry"));     
List<WebElement> options = selectElement.findElements(By.xpath("./option"));