2016-07-27 74 views
0

这是结构:如何FindElement与XPath硒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值?

+1

你想要可见的文本或href属性值吗? –

回答

1

随着一点点的调整,并从alecxe

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

您应该只是调整你体现了diva匹配元素:

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

帮我想你想链接的可见文本,您应该尝试使用.Text,如下所示: -

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