问题描述
String wb = driver.findElement(By.xpath("//div[@class='gb_h gb_i']/a")).getAttribute('href');
以上代码给出错误 Invalid character constant
我想使用 java
href
解决方法
您应该将 getAttribute('href')
更改为 getAttribute("href")
所以它应该是String wb = driver.findElement(By.xpath("//div[@class='gb_h gb_i']/a")).getAttribute("href");
getAttribute()
方法接收 String
。
在 Java 中,String
由 " "
定义,而 Character
由 ' '