Dom 使用Selenium自动单击JavaScript链接
我试图自动点击网页上异步运行的数据库的第2页。使用Xpath时:Dom 使用Selenium自动单击JavaScript链接,dom,xpath,selenium,automation,selenium-ide,Dom,Xpath,Selenium,Automation,Selenium Ide,我试图自动点击网页上异步运行的数据库的第2页。使用Xpath时: //id('standardView')/x:div[3]/x:div[3]/x:a[1] 我得到以下错误: [error] Invalid xpath [2]: //id('rightMenu')/x:div[3]/x:div[3]/x:a[1] 因此,我尝试使用DOM查找其路径,下面的代码显示了使用Firebug运行时推送的实际链接 main = document.getElementById("rightMenu"
//id('standardView')/x:div[3]/x:div[3]/x:a[1]
我得到以下错误:
[error] Invalid xpath [2]: //id('rightMenu')/x:div[3]/x:div[3]/x:a[1]
因此,我尝试使用DOM查找其路径,下面的代码显示了使用Firebug运行时推送的实际链接
main = document.getElementById("rightMenu"); mainCont = main.contentDocument;
paging = mainCont.getElementsByTagName("a"); pageTwo = paging[0];
Firebug将显示:
<a href="javascript:chgPage(2);">
而只是简单地记录动作并没有发现按钮被按下。我似乎找不到解决办法。有什么见解吗,朋友们 有点奇怪。尝试使用
/*[@id='standardView']/div[3]/div[3]/a[1]
但是尽量使用不带索引的选择器,并且尽可能短
//a[@href='javascript:chgPage(2);']
或
//*[@id='standardView']///a[@href='javascript:chgPage(2);']
这些插件也可以工作(如果它们是唯一的,请使用firebug的firepath插件进行检查)您可以发布一段html吗?谢谢,Alexander!我使用了//a[@href='javascript:chgPage(2);'],它工作得非常好。
[error] Unexpected Exception: fileName -> chrome://selenium-ide/content/selenium-
core/scripts/selenium-api.js, lineNumber -> 2535, columnNumber -> 45