C# 如何在Selenium PhantomJS C中通过Xpath查找元素#

C# 如何在Selenium PhantomJS C中通过Xpath查找元素#,c#,winforms,selenium,xpath,phantomjs,C#,Winforms,Selenium,Xpath,Phantomjs,结构如下: <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:1

结构如下:

<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>

是否可以获得
http://Please.Get.Me

您应该调整表达式以匹配
div
中的
a
元素:

driver1.FindElement(By.XPath(".//*[@id='debugTxt']/a")).GetAttribute("href");

您只需调整表达式以匹配
div
中的
a
元素:

driver1.FindElement(By.XPath(".//*[@id='debugTxt']/a")).GetAttribute("href");

在alecxe的帮助下稍作调整

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;

我认为您需要链接的可见文本,您应该尝试使用
.text
,如下所示:-

driver1.FindElement(By.XPath(".//*[@id='debugTxt']/a")).Text;

您想要可见文本还是href属性值??您想要可见文本还是href属性值??