简体   繁体   中英

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(.,'ledak.e.v@yandex.by')]]

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

final String StrEmailToTest = "ledak.e.v@yandex.by";
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.

您的XPath不应该是:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM