Java Selenium,如何从链接WebElement获取linkText(锚) [英] Java Selenium, how to get linkText (anchor) from link WebElement
本文介绍了Java Selenium,如何从链接WebElement获取linkText(锚)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含通过url找到的链接的WebElement.我可以通过以下方式提取网址:
I have a WebElement containing link found by url. I can extract url by:
element.getAttribute("href");
但是问题是:如何提取它的锚点,我正在尝试这样:
But the question is: how to extract it's anchor, I'm trying like this:
webElement.getAttribute("linkText");
它给了我空值.我100%确信此链接具有锚点.有什么办法获得锚点吗?它更复杂,但是示例简化的代码可能如下所示:
It gives me null value. I'm 100% sure this link has an anchor. Is there any way to get anchor ? It's more complicated, but example simplified code could look like this:
WebDriver driver = new FirefoxDriver();
driver.get("http://stackoverflow.com/questions/tagged/java");
WebElement link = driver.findElement(By.linkText("Bicycles"));
System.out.println(link.getAttribute("href")); // shows http://bicycles.stackexchange.com/
System.out.println(link.getAttribute("linkText")); // shows null
推荐答案
尝试一下:
System.out.println(link.getText());
这篇关于Java Selenium,如何从链接WebElement获取linkText(锚)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文