Sudhir
Sudhir

Reputation: 154

Selenium: Validating label testing

First-all, I apologize if this question is already answered. I am trying to automate simple login page for aribaweb application. The following source of my web page for login label.

<td class=ffl>
<label for=_$eseed>Login Name:</label></td>

Java source code: I am trying to find out with below piece of code. But, I am not able to go through.

iedriver.findElement(By.id("Login Name")).sendKeys("username"); 

I have tried using IDE as well, to check label value. I am seeing same issue [error] Element id=_$eseed not found

Any help in this regard is much appreciated.

Upvotes: 0

Views: 2824

Answers (2)

nilesh
nilesh

Reputation: 14287

Login Name: is not an id attribute. It is text. Instead you need to use the for attribute to locate the element. The other important thing is that you CANNOT send keys to label tags. There must be an input tag (or equivalent) next to the label where you want to send the text to.

WebElement label = driver.findElement(By.cssSelector("label[for='_$eseed']"));
s.o.p(label.getText());

If you provide html around the label consisting of input, I could point you on how to send keys.

Edit Based on your html, this is what you need,

WebElement login = driver.findElement(By.id("_$eseed"));
login.sendKeys("my_username");

Upvotes: 0

Ant&#39;s
Ant&#39;s

Reputation: 13811

Can you give whole source code?

I think this is where the problem is:

iedriver.findElement(By.id("Login Name")).sendKeys("username");

is wrong. You should give your HTML element id to By.id. Not your label string.

You can use FireBug to find HTML elements ids,css and more.

Upvotes: 3

Related Questions