如何从mailview webdriver获取价值

时间:2015-07-06 05:58:31

标签: selenium-webdriver webdriver

<div class="mailview" style="margin-right:18px;">

    Dear Customer,<br><br>
    Greetings from Calling Cards!.<br><br>

    We've created a new Calling Cards account for you.
    <br><br>
    Your Authentication Code is: 125412 <br><br>
    Click the following link and enter the authentication code to activate your Account: <a href="http://domain.com/Account/CustomerActivation/bedehhhh9ab7-b016h6hf0-4h6h68bf-a9hhh68-5dbd4hh3e77d7d"> Click 

    Here </a>.

    <br>
    <br>

    Please contact us if you have any questions or need further assistance.

     <br><br>Thank you for your business with us!<br>




            </div>

在此我想要验证码,我点击链接(点击这里),将能够将该代码发送到其他窗口的文本框,

是否可能,如果是的话,代码最受欢迎。

感谢Advace!

1 个答案:

答案 0 :(得分:0)

的Java代码
   WebElement element = driver.findElement(By.xpath("//div[@class='mailview']"));
    Pattern codePattern = Pattern.compile("(.*)(Your Authentication Code is: )(\\d+)(.*)", Pattern.DOTALL | Pattern.MULTILINE);
    Matcher m = codePattern.matcher(element.getText());
    if (m.matches()) {
        String code = m.group(3);
        System.out.println(code);
    }