0

I created one test case from FireFox and executed. It working fine,

I exported that as Java test case. I run in Eclipse, but it not working. I am getting error like this:

org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"link text","selector":"Incidents"}

My test case:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://myapphost:8080/" />
<title>IncidentsListTest22</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">IncidentsListTest22</td></tr>
</thead><tbody>
<tr>
    <td>open</td>
    <td>/myapp/login/auth?usrMsg=SE</td>
    <td></td>
</tr>
<tr>
    <td>type</td>
    <td>id=username</td>
    <td>username</td>
</tr>
<tr>
    <td>type</td>
    <td>id=password</td>
    <td>password</td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>id=loginForm_submit</td>
    <td></td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>link=Incidents</td>
    <td></td>
</tr>

</tbody></table>
</body>
</html>

MY POM is

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>myapp-selenium-test</groupId>
    <artifactId>myapp-selenium-test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <description>Tests the UI for rmsportal.</description>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.39.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>2.39.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>2.39.0</version>
        </dependency>
    </dependencies>
</project>

My test case is:

@Test 
public void testIncidentsList() throws Exception { driver.get(baseUrl + "myapp/login/auth?usrMsg=SE"); driver.findElement(By.id("username")).clear();
  driver.findElement(By.id("username")).sendKeys("username");
  driver.findElement(By.id("password")).clear();
  driver.findElement(By.id("password")).sendKeys("password");
  driver.findElement(By.id("loginForm_submit")).click();
  driver.findElement(By.linkText("Incidents")).click(); 
}

HTML page

<a class="dc-mega" href="#"> 
  Network Details 
  <span class="dc-mega-icon"></span> 
</a> 
<div class="sub-container non-mega" style="left: 138px; top: 31px; z-index: 1000;"> 
<ul class="sub" style="display: none;"> 
<li class="">
  <a href="/myapp/incident/list">Incidents</a> 
</li>
4
  • It tells you it can't find a link whose text is 'Incidents'. It will be difficult for us to help without viewing the DOM of the page at this moment (at least the source HTML where the element lives) Commented Jan 8, 2014 at 8:49
  • It working for with html test case. "Incidents" exist in html page, but not direct one it exist in one of the menu bar items"Details" tab. Commented Jan 8, 2014 at 9:05
  • My test case is @Test public void testIncidentsList() throws Exception { driver.get(baseUrl + "myapp/login/auth?usrMsg=SE"); driver.findElement(By.id("username")).clear(); driver.findElement(By.id("username")).sendKeys("username"); driver.findElement(By.id("password")).clear(); driver.findElement(By.id("password")).sendKeys("password"); driver.findElement(By.id("loginForm_submit")).click(); driver.findElement(By.linkText("Incidents")).click(); } Commented Jan 8, 2014 at 9:07
  • <a class="dc-mega" href="#"> Network Details <span class="dc-mega-icon"></span> </a> <div class="sub-container non-mega" style="left: 138px; top: 31px; z-index: 1000;"> <ul class="sub" style="display: none;"> <li class=""> <a href="/myapp/incident/list">Incidents</a> </li> Commented Jan 8, 2014 at 9:19

2 Answers 2

1

<a href="/myapp/incident/list">Incidents</a> is a child of a ul tag that seems to be invisible (<ul class="sub" style="display: none;">) for webdriver. You'll have to make it visible first...

Sign up to request clarification or add additional context in comments.

Comments

0

Selenium is in my experience very flaky when finding elements. I recommend trying XLT which has a very good Firefox plugin and exports JUnit testcases that you can run to test your page.

1 Comment

Selenium isn't flaky at all. It's up to the tester to know what is doing. I use Selenium on a massive basis, and always find a way to identify and find my elements

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.