-1

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

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

4

1 回答 1

0

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

于 2021-05-01T19:21:24.320 回答