开发者

Is there any method in selenium to get that text is a "Link" or simple text

I开发者_开发知识库s there any method in selenium to get that text is a Link or simple text


I assume that you get innerText of element and now want to validate whether it is under node.

Consider following HTML snippet for this -

"<a title=\"Junior TSG Application Engineer at Two Sigma Investments. Click to learn more.\" target=\"_blank\" " +
            "href=\"http://careers.stackoverflow.com:80/jobs/10467/junior-tsg-application-engineer-two-sigma-investments?campaign=PrettyTopspot\"> " +
            "Junior TSG Application Engineer<br> <span class=\"company\">Two Sigma Investments</span><br> <span class=\"location\">New York, NY</span> </a>";

Here innerText is - "Junior TSG Application Engineer"

You can get page html using getHTMLSource api of selenium and then can use Jsoup to find out if its in anchor tag, i.e. -

Document document = Jsoup.parse(selenium.getHTMLSource);
    Element element = document.select("a:contains(Junior TSG Application Engineer)").first();
    System.out.println(element.nodeName()); // You could do assertion here

On a different note, do you know Selenium questions would have their dedicated home at - https://sqa.stackexchange.com/ You might like to post your question here.


If you are looking for something like isThisLink(String textToBeValidated), then no. Selenium doesn't have such a method. You will have to write custom code to validate that.


You can use is_element_present('link=' + text). This will return true if text is a link otherwise false. Caution: You need to escape special characters in text. While testing this I was looking for a link that had a question mark in it and it was not found.


You can user getText() method in the below way:

selenium.getText("ID or xpath");

Happy Learning , Happy Sharing...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜