我试图使用机器人框架在html标签上找到一个元素。我想点击第一个元素是什么元素。
例如
在文本字段中输入文本,然后输入密钥输入
该项目会显示,我想点击第一项但我不能
我的机器人代码
.factory('cacheInterceptor', ['$cacheFactory', function($cacheFactory) {
return {
request: function(config) {
if (config.cache) {
// if we have stored this request, return it, else let the request happen naturally and cache after
// Things I don't know:
// How to return existing cache data and prevent the reqeust from happening
// Cache the data I get back from a HTTP request
}
return config;
}
};
}])
我的HTML标记
Open Browser http://www.tarad.com chrome
Wait Until Element Is Visible id=keyword
Input Text id=keyword dog
Press Key id=keyword \\13
Wait Until Element Is Visible id=wrapper_body_all
Element Should Be Visible id=wrapper_body_all
Click Element xpath=//div[id='warpper_all']/div[id='wapper_body_all']//ul/il//img[constains(@src,'//img.trd.cm/120/120/sumpow/img-lib/spd_20140314140410_b.jpg')]
答案 0 :(得分:1)
请注意,这是一个非常脆弱的Xpath,但它会完成你想要实现的工作:
Open Browser http://www.tarad.com chrome
Wait Until Element Is Visible id=keyword
Input Text id=keyword dog
Press Key id=keyword \\13
Wait Until Element Is Visible id=wrapper_body_all
Element Should Be Visible id=wrapper_body_all
Wait Until Page Contains Element xpath=(//div[@id='wrapper_body_all']/div/div[3]/div/div/div/div[2]/ul/li/div/div/a/img)[1]
Click Image xpath=(//div[@id='wrapper_body_all']/div/div[3]/div/div/div/div[2]/ul/li/div/div/a/img)[1]
这个机器人代码适用于我,它进入网站,然后输入" dog"搜索,然后单击第一个图像结果。 如果你想找到第二个,第三个等 - 改变最后一个数字。例如:
xpath=(//div[@id='wrapper_body_all']/div/div[3]/div/div/div/div[2]/ul/li/div/div/a/img)[5]
会找到第5个结果。只需更改[5]
的位置即可。此外,在你的机器人中确保它显示我刚发布的整个xpath。这包括xpath=
有任何问题请问。