首页 > 解决方案 > 上面的代码给出了错误 Invalid character constant in selenium with java

问题描述

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

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

标签: javaseleniumautomated-testsunderscore-java

解决方案


您应该更改getAttribute('href')为,getAttribute("href")因此它应该是
String wb = driver.findElement(By.xpath("//div[@class='gb_h gb_i']/a")).getAttribute("href");
getAttribute()方法接收String
在 JavaString中是由" "whileCharacter定义的' '


推荐阅读