Reputation: 49
I use firepath
due to locate element and get xpath
, but in eclipse
, it does not work. Also Tried other variants referring to http://www.guru99.com/xpath-selenium.html which also work in firepath
, but eclipse
they didn't find them like example 1
fragment of code:
<span class="registration ng-scope" translate="navbar_component.menuItems.sign_up" ng-click="$ctrl.goToPage('registration')" role="button" tabindex="0">Sign up</span>
<span class="registration ng-scope" translate="navbar_component.menuItems.sign_in" ng-click="$ctrl.goToPage('sign-in')" role="button" tabindex="0">Sign in</span>
That's what I have from firepath
:
driver.findElement(By.xpath(".//*[@id='sign-in']/span[2]/span[2]")).click();
(that's what fire path gave me)
Examples of my xpath
1
.//*[@class='registration ng-scope']//following-sibling::span
I will be very grateful if you can advice me what I can use to locate "Sign in"
button.
The exception received:
Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700' System info: host: 'WS250', ip: '192.168.84.165', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121' Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, firefoxOptions={args=[], prefs={}}, appBuildId=20170125094131, version=, platform=XP, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, processId=2108, browserVersion=51.0.1, platformVersion=10.0, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=windows_nt}] Session ID: 14605620-ee13-4766-8edf-7b6cf31b35f6
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:127)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:93)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:42)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at Selenium.test.SignIN.main(SignIN.java:14)
Upvotes: 1
Views: 1383
Reputation: 52665
You can simply use text content of target element as:
driver.findElement(By.xpath("//span[text()='Sign in']")).click();
You might need to wait until element is visible:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text()='Sign in']")).click();
Upvotes: 1