selenium中用于单击元素的xpath
这是HTML代码,对于方框,请告诉我如何为方框中的任何元素找到正确的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
农业和矿业-农业和牧场
农业和矿业-捕鱼、狩猎和诱捕
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"));