【发布时间】:2021-06-14 11:06:40
【问题描述】:
我正在尝试在网站上找到一个元素并获取所有元素。为此,我使用硒化物/硒。我正在寻找的元素不能被一个类定位,因此我试图找到一个具有两个类(父类和子类)的元素。仅使用 Selenide,我可以使用以下方法轻松定位元素:
SelenideElement basketIcon = $(By.className("buttons")).$(byClassName("btn-cart"))
这肯定会给我一个元素。但是我怎样才能找到一个元素数组呢?
List<SelenideElement> productName1 = WebDriverRunner.getWebDriver().findElements(By.className("")); 但它不起作用,我也尝试过:List<WebElement> productName = WebDriverRunner.getWebDriver().findElements(By.className("buttons")); 但在这里我如何添加另一个类来定位元素? $(byClassName("btn-cart"))?还是有其他方法可以做到这一点?
我也尝试过使用ElementsCollection elements = WebDriverRunner.getWebDriver().findElements(By.className(""));,但它不起作用...
编辑: 我有一个名为“DriverFactory”的类,用于打开浏览器:
public static void openBrowser(String browserName, String url) throws Exception {
WebDriverManager.chromedriver().browserVersion(chromeversion).setup();
Configuration.browser = "Chrome";
Configuration.startMaximized = true;
driver.get(url);
}
另一个类,我在其中定义定位器:
public class EE_MonitorCategoryElements extends DriverFactory {
protected static List<WebElement> productName = getWebDriver().findElements(By.id("asddsa"));
}
还有一个测试类:
@Test
public void ads() throws Exception {
DriverFactory.openBrowser("Chrome", "https://google.ge");
}
当我使用“getWebDriver()”添加最后一个元素定位器并尝试运行测试时,它给了我一个错误:没有测试被绑定,并且我删除/注释 getWebDriver 行,它正在工作
【问题讨论】:
标签: java selenium intellij-idea css-selectors selenide