开发者

Selenium.getText() problem

开发者 https://www.devze.com 2023-03-12 01:33 出处:网络
Hope someone can help me here? Having an issue getting text that\'s located inside a tag but After another tag...

Hope someone can help me here?

Having an issue getting text that's located inside a tag but After another tag...

<li><b>**Duration Held:**</b> 5 Years </li>

I need to return the "5 Years" part of the Text but selenium.getText() returns the whole <li> contents, which is correct, but I need the text after the </b> tag but can't figure out a way to achieve this task?

Has anyone come across this type of scenario, if so, what was done to get the text after a </b> but still inside the <li> tag ???

I'm stumped, Any help i开发者_开发技巧s appreciated!

Cheers!


You can easily use regex to extract what you want. such as;

            String st = selenium.getText();
        Pattern pt = Pattern.compile("</b>([^<]+)</li>");
        Matcher matcher = pt.matcher(st);
        if (matcher.matches())
            System.out.println(matcher.group(1));
0

精彩评论

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

关注公众号