[英]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:
我在FirePath中创建了XPath选择器,它是:
//a[@href='http://i.yandex.ru/'][span[contains(.,'ledak.e.v@yandex.by')]]
But Selenium-RC can't locate this element. 但是Selenium-RC找不到此元素。 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" 它返回“ false”
Could you tell me, what am I doing wrong? 你能告诉我,我做错了什么吗?
UPD. 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.
我在这里上传了* .maft-文件: http ://depositfiles.com/files/lhcdh2wtl不要担心,屏幕上有一些俄语字符。
您的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().
如果是这样,请使用waitForElementPresent()。 If not, try changing the method of element identification - use id or name and then try to execute it.
如果不是,请尝试更改元素标识的方法-使用id或name,然后尝试执行它。 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".
为了确保您的xpath正确,请在Firefox的Selenium IDE /插件中,键入元素的路径(在命令字段中输入一些随机命令),然后单击“查找元素”。 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.
如果没有,您将不得不要求Selenium等待直到元素被加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.