I'm pretty new to Selenium, and am facing some difficulty clicking a button using Chrome WebDriver and xpath (and also by copying FULL xpath). I've searched and read the other posts, but still am not sure what's wrong. i've tried using the By.className and By.cssSelector functions, but still can't get it to work.
Here's my code (xpath extracted by inspecting source > inspecting element > copy xpath):
webDriver.findElement(By.xpath("//*[@id='contentPageWrapper']/div[2]/count-survey-component/div/div[3]/div/button/span)")).click();
and here is the error i'm getting
Session ID: 7788e90631cad702049a4e60e946b7ae
*** Element info: {Using=xpath, value=//*[@id='contentPageWrapper']/div[2]/count-survey-component/div/div[3]/div/button/span)}
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
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 EnterDataToWeb.enterDataToWeb(EnterDataToWeb.java:20)
at Main.main(Main.java:103)
Here is the source
<button class="pull-right mat-blue mat-raised-button ng-star-inserted" mat-raised-button=$0>
<span class="mat-button-wrapper">Add new</span>
<div class="mat-button-ripple mat-ripple" matripple=""></div>
<div class="mat-button-focus-overlay"></div>
</button>
Can anyone help me out?
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire