我还在尝试使用selenium,我是一个从事Selenium自动化POC工作的SAP人。我的要求是单击下拉菜单并从droplist中选择一个值。
我广泛地查看了之前的帖子,但没有找到任何答案。我已经尝试了帖子中的所有建议,但似乎没有一个对我有效。
请告诉我如何访问这个下拉值。
HTML代码与我试图访问的元素一起附加在图片中
我的selenium代码:
driver.switchTo().frame(driver.findElement(By.name("SMFrame")));
System.out.println("TExt" + driver.findElement(By.xpath("//div[@class='file-type']")).getText());错误:
error -- > no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class='file-type']"}发布于 2019-10-19 08:52:47
假设您正确地进入了iframe
现在,您选择的是实际dropdown元素( select-dropdown标记)之上的div。您可能想尝试更改xpath以搜索标记,如下所示:
//div[@class='file-dropdown']/select-dropdown此外,您还应该创建一个如下所示的dropdown对象。然后在其上调用一个方法来选择您要查找的下拉选项:
Select dropdown = new Select(driver.findElement(By.xpath("//div[@class='file-dropdown']/select-dropdown");
System.out.println(dropdown.selectByVisibleText("text that you are looking for in the options")); 这是对如何做到这一点的一个很好的解释:https://www.javatpoint.com/selenium-webdriver-handling-drop-downs
https://stackoverflow.com/questions/58459309
复制相似问题