Reputation: 37
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
Not Available Not Available Not Available Not Available Not Available Not Available Not Available Not Available Not Available Not Available Not Available
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)
this line contains at automation.ExampleScanario.main(ExampleScanario.java:52)
driver.findElement(By.xpath("//label[@class='checkbox ng-binding']//input[@type='checkbox']")).click();
Upvotes: 0
Views: 180
Reputation: 4035
Instead of Thread.sleep(750); You should use Explicit wait for same. Here 750 is less than 1 second, Web page need some time to load, We can't define it with specific time.
WebDriverWait wait=new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("Your Element")).click());
Upvotes: 1
Reputation: 23
In Automation testing, XPath is the last option I use to locate the element. XPath is nothing but a possible unique path for an element, which contains a sequence of tags to form a unique path. It can be changed at any time.
I Suggest you test XPath while your test is running. Add a sleep time just before you use XPath and Inspect again. You will definitely get a different path this time.
Upvotes: 0