0

I'm newbie in selenium webdriver and today i have some issues with my sample login and logout scenario. I want to get element in gmail but eclipse always notice error. Element i want to get (my email test)

And here is my xpath://*[@id='gb']//descendant::div[@class='gb_vb'] . But when find it, eclipse always notice error.

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: //*[@id='gb']//descendant::div[@class='gb_vb']
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
System info: host: 'Alex', ip: '192.168.1.7', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_112'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, firefoxOptions={args=[], prefs={}}, appBuildId=20160623154057, version=, platform=XP, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, browserVersion=47.0.1, platformVersion=10.0, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=Firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=Windows_NT, device=desktop}]
Session ID: 2fd78092-bf4a-4095-8a32-1a2e1d22ed3e
*** Element info: {Using=xpath, value=//*[@id='gb']//descendant::div[@class='gb_vb']}
    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.RemoteWebDriver.findElement(RemoteWebDriver.java:368)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:473)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
    at CucumberTest.LoginTestFunction.WaitandElement.findE(WaitandElement.java:19)
    at CucumberTest.LoginTestFunction.SeleniumTest.main(SeleniumTest.java:30)
Alex Le
  • 93
  • 3
  • 13

3 Answers3

0

Are you opening the menu that the element is contained in first? I've just tried this, and it will only work if you open the containing menu before trying to find the element containing your email address beforehand e.g. (C# for the example):

IWebElement popupMenu = driver.FindElement(By.XPath("//*[@id=\"gb\"]/div[1]/div[1]/div[2]/div[4]/div[1]/a/span"));
popupMenu.Click();

Then use your code above to find the element you're looking for.

Josh
  • 697
  • 7
  • 18
  • you r right, need to show up this menu first and then get text it. But i found my issue about explicit wait. – Alex Le Dec 20 '16 at 13:44
0

Try this XPath:

//div[@class="gb_vb"][contains(text(), "@gmail.com")]
Andersson
  • 51,635
  • 17
  • 77
  • 129
0

In that case, you should use Explicit Waits

Cause maybe web browser need time to load all element (for example: lazy load, load more, ajax ...)

//wait for 10 seconds
WebDriverWait logWait = new WebDriverWait(driver, 10);
logWait.until(ExpectedConditions.presenceOfElementLocated(by));  
//now you can find element
driver.findElement(By.xpath("//*[@id='gb']//descendant::div[@class='gb_vb']"));
Community
  • 1
  • 1
coffeduong
  • 1,443
  • 1
  • 10
  • 11