如何select下拉菜单中的一个选项
How to select a option in the drop-down menu
我使用 selenium、WebDriver、Intellij、Junit4、ChromeDriver、PageObject。
正在测试此站点:http://store.demoqa.com/products-page/product-category/。
如果我手动点击 link "Product Category",您会看到,页面会重新加载,下拉菜单会消失片刻。其实你只需要将鼠标悬停在 link "Product Category" 上,然后使用 action.moveToElement() 单击 "Accessories",但我不知道如何编写代码。你能给我写代码吗?
这是我的代码:
public ProductPage clickOnAccessories(){
//Click on link “Product Category” than “Accessories” on website navigation
driver.findElement(By.id("menu-item-33")).click();
driver.findElement(By.id("men34u-item-34")).click();
}
给你,
Actions act = new Actions(driver);
act.moveToElement(driver.findElement(By.xpath("//a[text()='Product Category']")));
act.perform();
driver.findElement(By.xpath("//a[text()='Accessories']")).click();
我使用 selenium、WebDriver、Intellij、Junit4、ChromeDriver、PageObject。
正在测试此站点:http://store.demoqa.com/products-page/product-category/。
如果我手动点击 link "Product Category",您会看到,页面会重新加载,下拉菜单会消失片刻。其实你只需要将鼠标悬停在 link "Product Category" 上,然后使用 action.moveToElement() 单击 "Accessories",但我不知道如何编写代码。你能给我写代码吗?
这是我的代码:
public ProductPage clickOnAccessories(){
//Click on link “Product Category” than “Accessories” on website navigation
driver.findElement(By.id("menu-item-33")).click();
driver.findElement(By.id("men34u-item-34")).click();
}
给你,
Actions act = new Actions(driver);
act.moveToElement(driver.findElement(By.xpath("//a[text()='Product Category']")));
act.perform();
driver.findElement(By.xpath("//a[text()='Accessories']")).click();