当我尝试单击应用程序中的按钮时,get org.openqa.selenium.webdriverexception



got org.openqa.selenium.webdriverexception当我尝试单击应用程序中的按钮时。操作是单击按钮,执行停止并在以下错误之下:

Select dropdown= new  Select(driver.findElement(By.xpath("html/body/section/div/div/div/div[5]/div/div/div[1]/ul/li[9]/span/select")));
        dropdown.selectByIndex(1);
        Thread.sleep(5000L);
        //driver.findElement(By.xpath("html/body/section/div/div/div/div[5]/div/div/div[2]/p[2]/button")).click();
        WebElement element= driver.findElement(By.xpath("html/body/section/div/div/div/div[5]/div/div/div[2]/p[2]/button"));
        JavascriptExecutor executor = (JavascriptExecutor) driver;
        executor.executeScript("arguments[0].click();", element);

错误日志是:

线程"主" org.openqa.selenium.webdriverexception:未知错误:元素... 在点(337,11(无法单击。其他元素会单击:... (会话信息:chrome = 58.0.3029.81(

任何建议都非常感谢。

这是发生的,因为在脚本执行过程中,元素不可见,如果向下滚动一点,则可以看到元素。

因此,简而言之,您需要诱导一个小脚本以向下滚动。在单击语句之前使用此。

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,250)", "");

让我知道这是否有帮助,或者在任何查询中。欢呼!

相关内容

最新更新