0

I am writing a selenium webdriver script . Below is the src code.

driver.get(baseUrl); 
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
driver.findElement(By.id("txtUserDefault")).clear(); 
// page one code works fine in unix...login page 
// below is the partialLinkText which is working fine in eclipse but giving error in jar execution in unix 
driver.findElement(By.partialLinkText("101")).click();

First page is login page and second page has below source code

<html>
  <head>
    <title>Test app</title>
  </head>
  <body>
    <center>
      <h1> Country selection</h1>
        <table border=1 width=450>
          <tr bgcolor="#BBBBBB">
            <td><b>PU</td><td><b>Department</td></tr>
          <tr><td>HK1</td><td><a href="https://www.test1.com">101</a>&nbsp(Country1)</td></tr>
          <tr><td>SG1</td><td><a href="https://www.test2.com">102</a>&nbsp(Country2)</td></tr>
        </table>
      </center>
    </center>
  </body>
</html>

When i run the code through eclipse IDE , it runs fine . But when I export the jar and run the same code through xvfb in unix , it is able to log in first page and go to 2nd page . On 2nd page it is throwing NoElementFoundException (trying to click hyperlink 101 and 102).

I tried same thing thorugh cssSelector, partiallinkText ,xpath . Works fine in eclipse but throws same error in unix .

drkthng
  • 6,651
  • 7
  • 33
  • 53
dan
  • 73
  • 1
  • 11
  • why are there two closing "center" elements but only one opening? And where is the Selenium source code? (I only see your html - which is a good start ;-) – drkthng Oct 30 '15 at 11:20
  • The source code has two closing braces /centre...know its wrong but cant help..below is the selenium code I am trying, thanks driver.get(baseUrl); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.findElement(By.id("txtUserDefault")).clear(); // page one code works fine in unix...login page // below is the partialLinkText which is working fine in eclipse but giving error in jar execution in unix driver.findElement(By.partialLinkText("101")).click(); – dan Oct 30 '15 at 12:27

1 Answers1

0

Maybe xvfb is loading "too slow", try waiting a bit for the element:

new WebDriverWait(driver, 30).until(ExpectedConditions.visibilityOfElementLocated(By.partialLinkText("101")));
driver.findElement(By.partialLinkText("101")).click();
drkthng
  • 6,651
  • 7
  • 33
  • 53
  • I gave a time wait of 200 secs but still same error . I am not able to understand how the same script is working fine in eclipse Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: Command duration or timeout: 200.07 seconds – dan Oct 30 '15 at 14:45
  • 1
    resolved finally. Issue was as below. it was stuck at first page only. it did not go to 2nd page, hence it was not able to find the element. Loginbtn is the classname for submit tab on first page driver.findElement(By.className("Loginbtn")).click(); => works in eclipse , does not work in xvfb driver.findElement(By.className("Loginbtn")).submit(); => works in eclipse and xvfb both – dan Nov 02 '15 at 16:02
  • @dan, that's an intersting issue! – drkthng Nov 02 '15 at 16:05