将错误显示为
(org.openqa.selenium.WebDriverException:未知错误:无法读取 属性'click'为null)
有人可以帮助我解决以下问题吗? 通过Java Script Executor单击元素
单击Java Script Executor方法:
public static void ClickByJS(WebElement element, WebDriver driver){
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", element);
}
以这种方式使用(driver.findElement By(Xpath))
:
WebElement titleDD = driver.findElement(By.xpath("//div[@aria-
owns='registrationPageTitleSelect-dropdown-list']"));
ClickByJS(titleDD, driver);
public static void ClickByJS(WebElement element, WebDriver driver)
{
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", element);
}
使用(FindBy())
@FindBy(xpath="//div[@aria-owns='registrationPageTitleSelect-dropdown-
list']")
WebElement SelectTitleDropDown;
public void ValidateSelectTitle()
{
ClickByJS(SelectTitleDropDown, driver);
}