I am using the following code using Java and Selenium:
public static void main(String[] args){
WebDriver driver;
DesiredCapabilities caps;
caps = new DesiredCapabilities();
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"lib/phantomjs.exe");
caps.setBrowserName(DesiredCapabilities.phantomjs().getBrowserName());
driver = new PhantomJSDriver(caps);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("https://www.cdp.net/en-US/Pages/CDPAdvancedSearchResults.aspx?k=microsoft");
WebElement element = driver.findElement(By.className("ms-vb2"));
String text = element.getText();
String href = element.getAttribute("href");
driver.manage().deleteAllCookies();
driver.quit();
System.out.println(text + " " + href);
}
The specific portion of the page I am trying with the code contains the following. I am trying to extract the href from class ms-vb2, which is https://www.cdp.net/en-US/Results/Pages/Company-Responses.aspx?company=11930:
<td class="ms-vb2"><a href="https://www.cdp.net/en-US/Results/Pages/Company-Responses.aspx?company=11930">Microsoft Corporation</a><br/>USA</td>
I am getting the text but I am not getting the href. How can I extract that?