Above code gives error Invalid character constant in selenium with java

227 Views Asked by At

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

Above code gives error Invalid character constant
I want to fetch href from html code using java

1

There are 1 best solutions below

0
On

You should change getAttribute('href') to getAttribute("href") so it should be
String wb = driver.findElement(By.xpath("//div[@class='gb_h gb_i']/a")).getAttribute("href");
getAttribute() method receives String.
In Java String is defined by " " while Character is defined by ' '