我需要找到a href
元素並返回其內容。找不到元素
這裏是源代碼中的內容:
<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>
的事業部,這是唯一的元素
嘗試打印outerHTML我可以找到:
IWebElement pisso = driver.FindElement(By.XPath("//*[@id="responseDiv"]"));
string outerHTML = pisso.GetAttribute("outerHTML");
但它不返回HREF內容,只有這個:
<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">
<p>Your browser does not support iframes.</p></iframe>
</div>
我試過直接找到href元素,但它找不到它,Cs sSelector爲:
IWebElement pisso = driver.FindElement(By.CssSelector("body > font > a"));
也試過的XPath爲:
IWebElement pisso = driver.FindElement(By.XPath("/html/body/font/a"));
它返回找不到元素異常 –
可見的元素中的一切:
使用解決了嗎?或者在彈出窗口中? – jaredgilmore
看起來是在一個iFrame,所以你需要切換到該iFrame。 – smit9234