Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find element

I need to find the a href element and return its contents.

Here are the contents in the source:

<div id="responseDiv" style="background-color:#EBECED;width: 450px;">
<iframesrc="/iframe.asp" width="575" height="120" frameborder="0" 
marginwidth="1" marginheight="1" scrolling="no">
#document
<html>
<head> </head>
<body marginwidth="1" marginheight="1">
<font size="3" style = "letter-spacing: 0pt" color="#336699" face="Arial"
<a href="blablabla?subject=blebleble" target="_blank">[email protected]</a>
</font>
</body>
</html>
</iframe>
</div>

Tried printing outerHTML of the Div, which is the only element I can find:

IWebElement pisso = driver.FindElement(By.XPath("//*[@id="responseDiv"]"));
string outerHTML = pisso.GetAttribute("outerHTML");

But it doesn't return the href contents, only this:

<div id="responseDiv" style="background-color:#EBECED;width: 450px;">

<iframe src="/iframe.asp" width="575" height="120" frameborder="0" marginwidth="1" marginheight="1" scrolling="no">
  &lt;p&gt;Your browser does not support iframes.&lt;/p&gt;</iframe>

</div>

I've tried finding the href element directly but it can't find it, CssSelector as:

IWebElement pisso = driver.FindElement(By.CssSelector("body > font > a"));

Also tried XPath as:

 IWebElement pisso = driver.FindElement(By.XPath("/html/body/font/a"));
like image 391
Awesome Sauce Avatar asked Apr 06 '26 19:04

Awesome Sauce


1 Answers

You need to get the attribute value via .getAttribute(value), which returns a String.

So try this:

String hrefValue = driver.FindElement(By.CssSelector("#responseDiv body font a")).getAttribute("href");
like image 91
jaredgilmore Avatar answered Apr 08 '26 14:04

jaredgilmore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!