[英]Selenium WebDriver C# not find element by FindElement(by.xpath)
[英]How to FindElement By Xpath in Selenium PhantomJS C#
结构如下:
<div id="footer">
<div id="debugTxt" style="color:blue;">Wed Jul 27 2016 10:06:12 GMT+0800 (Sample)Sample<br>
Sample<br>
Wed Jul 27 2016 10:06:12 GMT+0800 (Sample) Sample<br>
Wed Jul 27 2016 10:06:12 GMT+0800 (Sample) Sample!<br>
Wed Jul 27 2016 10:06:12 GMT+0800 (Sample) <br>
DataTOGET:<a href="http://Please.Get.Me" target="_blank">http://Please.Get.Me</a><br>
</div>
</div>
这就是我想要做的:
driver1.FindElement(By.XPath(".//*[@id='debugTxt']")).GetAttribute("value");
是否可以获取http://Please.Get.Me
的值?
您只需要调整表达式以匹配div
中的a
元素:
driver1.FindElement(By.XPath(".//*[@id='debugTxt']/a")).GetAttribute("href");
稍加调整并得到alecxe的帮助
driver1.FindElement(By.XPath("//*[@id='debugTxt']//a")).GetAttribute("href");
我认为您想要链接的可见文本,则应尝试使用.Text
,如下所示:-
driver1.FindElement(By.XPath(".//*[@id='debugTxt']/a")).Text;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.