Boolean run = true;
while(run)
{
if (nomore.contentEquals(tt))
{
driver.navigate().to("https://mettl.com/corporate/live-feed#/proctoringDashboard");
Thread.sleep(750);
driver.findElement(By.xpath("//label[@class='checkbox ng-binding']//input[@type='checkbox']")).click();
driver.findElement(By.xpath("//button[contains(text(),'Authorize')]")).click();
//Thread.sleep(1200);
System.out.println("Not Available");
}
else
{
//Thread.sleep(10000);
run = false;
System.out.println("Available");
break;
}
}
这是我的错误
Nov 23, 2018 10:22:08 AM org.openqa.selenium.remote.DesiredCapabilities firefox
INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
Starting ChromeDriver 2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a) on port 11629
Only local connections are allowed.
Nov 23, 2018 10:22:13 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
无法使用
无法使用
无法使用
无法使用
无法使用
无法使用
无法使用
无法使用
无法使用
无法使用
无法使用
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//label[@class='checkbox ng-binding']//input[@type='checkbox']"}
*** Element info: {Using=xpath, value=//label[@class='checkbox ng-binding']//input[@type='checkbox']}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:428)
at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
at automation.ExampleScanario.main(ExampleScanario.java:52)
该行包含
在Automation.ExampleScanario.main(ExampleScanario.java:52)
driver.findElement(By.xpath("//label[@class='checkbox ng-binding']//input[@type='checkbox']")).click();
最佳答案
而不是Thread.sleep(750);您应该使用Explicit等待。
这里750不到1秒,网页需要一些时间才能加载,我们无法在特定时间定义它。
WebDriverWait wait=new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("Your Element")).click());