gpt4 book ai didi

c# - 找不到元素

转载 作者:行者123 更新时间:2023-11-30 16:42:44 24 4
gpt4 key购买 nike

我需要找到 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">merkl@gmail.com</a>
</font>
</body>
</html>
</iframe>
</div>

尝试打印 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">
&lt;p&gt;Your browser does not support iframes.&lt;/p&gt;</iframe>

</div>

我试过直接查找 href 元素但是找不到,CssSelector as:

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

还尝试将 XPath 作为:

 IWebElement pisso = driver.FindElement(By.XPath("/html/body/font/a"));

最佳答案

需要通过.getAttribute(value)获取属性值,返回一个String

那么试试这个:

String hrefValue = driver.FindElement(By.CssSelector("#responseDiv body font a")).getAttribute("href");

关于c# - 找不到元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46202497/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com