首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RSelenium弹出窗口

RSelenium弹出窗口
EN

Stack Overflow用户
提问于 2018-02-28 14:48:59
回答 1查看 635关注 0票数 1

我试图在HTML页面中打开一个弹出链接:

代码语言:javascript
复制
<a class="popup-link" href="/PPI/displayRemarks.do?itemId=100582281" title="Add Remarks for the item" onclick="return false" id="anch_12">Add remarks</a>

我尝试使用ID查找元素:

代码语言:javascript
复制
remDr$findElement(using = 'id', "anch_12")

我收到这个错误:

代码语言:javascript
复制
Selenium message:{"errorMessage":"Unable to find element with id 'anch_12'","request":{"headers":{"Accept":"application/json, text/xml, application/xml, /","Accept-Encoding":"gzip, deflate","Content-Length":"32","Content-Type":"application/json","Host":"localhost:4567","User-Agent":"libcurl/7.56.0 r-curl/3.0 httr/1.3.1"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"id\",\"value\":\"anch_12\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/c6eac2b0-1bfd-11e8-8fbd-fbf94221e6d1/element"}}

错误摘要:

代码语言:javascript
复制
NoSuchElement Detail: An element could not be located on the page using the given search parameters. class: org.openqa.selenium.NoSuchElementException Further Details: run errorDetails method
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-28 14:55:00

带有itemId=100582281值的id anch_12以及href属性看起来是动态的。因此,您必须构建一个动态xpath,如下所示:

代码语言:javascript
复制
remDr$findElement(using = 'xpath', "//a[@class='popup-link' and contains(@href,'/PPI/displayRemarks.do?itemId=') and starts-with(@id,'anch_')]")
//or
remDr$findElement(using = 'xpath', "//a[@class='popup-link' and contains(@title,'Add Remarks for the item') and starts-with(@id,'anch_')]")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49032302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档