Eugene
Eugene

Reputation: 5543

Problems with element locating with XPath in Selenium-RC

I'm trying to perform very simple automated test. I created XPath selector in a FirePath, here it is:

//a[@href='http://i.yandex.ru/'][span[contains(.,'[email protected]')]]

But Selenium-RC can't locate this element. Code is:

final String StrEmailToTest = "[email protected]";
String linkEmailSelector = "//a[@href='http://i.yandex.ru/'][span[contains(.,'"+ StrEmailToTest + "')]]";
selenium.isElementPresent(linkEmailSelector);

and it returns "false"

Could you tell me, what am I doing wrong?

UPD. I've uploaded the *.maft - file here: http://depositfiles.com/files/lhcdh2wtl Don't be afraid, there are some russian characters on the screen.

Upvotes: 0

Views: 892

Answers (2)

Ozyman
Ozyman

Reputation: 513

My guess is that selenium is looking for the element even before it's loaded. Is it a dynamically loaded/generated element? If so, use waitForElementPresent(). If not, try changing the method of element identification - use id or name and then try to execute it. To make sure your xpath is correct, in the selenium IDE/plugin for firefox, type the path of the element(issue some random command for command field) and click on "Find Element". If it finds, then selenium has no problem finding it, given that the page/element is loaded or generated. If not, you will have to ask Selenium to wait till the element is loaded.

Upvotes: 0

Sjaak Trekhaak
Sjaak Trekhaak

Reputation: 4966

Shouldn't your XPath be:

"//a[@href='http://i.yandex.ru/']/span[contains(.,'"+ StrEmailToTest + "')]";

Upvotes: 1

Related Questions