求 selenium By.xpath 包含变量 解决方案

各位大侠,请帮忙看看这个问题我用java写seleniumBy.xpath元素定位,遇到xpath里面包含有变动的ID,想通过动态获取该ID先转成string再通过By.... 各位大侠, 请帮忙看看这个问题
我用java 写 selenium By.xpath 元素定位, 遇到 xpath 里面包含有变动的ID, 想通过 动态获取该ID 先转成string 再通过By.xpath 来定位, 编译报错 无法定位.
代码如下:
String tmp = "\"" + "//span[@class='bigbtn' and @eid='" + ID +"']" + "\"";
WebElement Bigbtn = driver.findElement(By.xpath(tmp));
异常如下:
Exception in thread "main" org.openqa.selenium.InvalidSelectorException: The given selector "//span[@class='bigbtn' and @eid='123']" is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: Unable to locate an element with the xpath expression "//span[@class='bigbtn' and @eid='123']" because of the following error:
[Exception... "The expression cannot be converted to return the specified type." code: "0" nsresult: "0x805b0034 (TypeError)" location: "<unknown>"]
若直接写 常量的内容, 是可以定位的
展开
 我来答
  • 你的回答被采纳后将获得:
  • 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
kanecake
2015-07-06 · TA获得超过396个赞
知道小有建树答主
回答量:260
采纳率:100%
帮助的人:191万
展开全部
这个异常是表示你的xpath表达式有误,把"\"" 去掉试试
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式