【问题标题】:Above code gives error Invalid character constant in selenium with java上面的代码给出了错误 Invalid character constant in selenium with java
【发布时间】:2021-05-01 14:46:29
【问题描述】:

String wb = driver.findElement(By.xpath("//div[@class='gb_h gb_i']/a")).getAttribute('href');

以上代码给出错误Invalid character constant
我想使用java从html代码中获取href

【问题讨论】:

  • 我的回答解决了你的问题吗?

标签: java selenium automated-tests underscore-java


【解决方案1】:

您应该将getAttribute('href') 更改为getAttribute("href") 所以它应该是
String wb = driver.findElement(By.xpath("//div[@class='gb_h gb_i']/a")).getAttribute("href");
getAttribute() 方法接收String
在 Java 中,String" " 定义,而 Character' ' 定义

【讨论】:

    猜你喜欢
    • 2023-02-20
    • 2014-03-09
    • 1970-01-01
    • 2019-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多