selenium icon indicating copy to clipboard operation
selenium copied to clipboard

NoSuchElementException: Unable to locate element in Selenium webdriver

Open shashi77 opened this issue 10 years ago • 2 comments

Meta -

OS: Windows 7 Selenium Version: 2.53 Browser: Firefox Browser Version: 31.0

Expected Behavior -

I should click on a "Register/Create an Account" link in a login page.

Actual Behavior -

Unable to locate element error is displayed org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"link text","selector":"Register/Create an Account"} Command duration or timeout: 0 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:03:00' Session ID: 8757a2e4-a195-4ce0-b043-0f6c3decacc8 Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=true, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=31.0}] at sun.reflect.GeneratedConstructorAccessor11.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352) at org.openqa.selenium.remote.RemoteWebDriver.findElementByLinkText(RemoteWebDriver.java:401) at org.openqa.selenium.By$ByLinkText.findElement(By.java:242) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344) at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:730) at org.openqa.selenium.support.ui.ExpectedConditions.access$0(ExpectedConditions.java:728) at org.openqa.selenium.support.ui.ExpectedConditions$3.apply(ExpectedConditions.java:106) at org.openqa.selenium.support.ui.ExpectedConditions$3.apply(ExpectedConditions.java:1) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)

HTML snippet of the web application <div class="widget-content widget-link-container" > <style> ... </style> <a class="widget-link" href="example.com"; target="_parent"> <span class="link-text">Register/Create an Account</span> </a> </div>

My Test script is pretty simple WebDriver driver=new FirefoxDriver(); driver.get("http://*****.com"); WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.presenceOfElementLocated((By.linkText("Register/Create an Account")))); driver.findElement(By.linkText("Register/Create an Account")).click(); or driver.findElement(By.xpath("//a[@href='********']")).click();

Steps to reproduce -

  1. Navigate to http://example.com
  2. Click on Register/Create an Account link in the login page.

Note: Above test script worked well in test environment but not in development environment. Test and Development environment specs are same.

Please help me out in this regard.

shashi77 avatar Jul 01 '16 15:07 shashi77

Have you tried to use the "partialLinkText" function instead of "linkText" ? Your text is surrounded by the element and maybe it has an impact on Selenium.

foxrafi avatar Jul 01 '16 15:07 foxrafi

Please provide a completely reproducible test case for us that would include a link to a page or html (including css / javascript) along with a WebDriver script to reproduce the issue. Without this there is little to nothing one can do to help with your issue. Please do not expect others volunteering their time to work at reproducing your issue.

When a reproducible test case is provided we can reopen the issue.

lukeis avatar Jul 01 '16 16:07 lukeis