如何打印通过硒中的"selectByVisibleText"方法选择的所选选项的文本 [英] How to print the text of the selected option choosen through 'selectByVisibleText' method in selenium

查看:280
本文介绍了如何打印通过硒中的"selectByVisibleText"方法选择的所选选项的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Selenium的新手,你们中的任何人都可以让我知道如何打印硒中'selectByVisibleText'中选择的值吗?

I am new to Selenium, could any one of you let me know how to print the value selected from 'selectByVisibleText' in selenium?

我已经在Facebook登录页面上运行了该测试,下拉菜单选择了生日.

I have run the test on Facebook login page, drop down for Birthday.

预先感谢.

推荐答案

一旦通过 selectByVisibleText()方法选择选项以打印值,则需要调用 getFirstSelectedOption()方法如下:

Once you select the option through selectByVisibleText() method to print the value you need to invoke getFirstSelectedOption() method as follows:

  • 代码块:

  • Code Block:

Select month_dd = new Select(month_dropdown);
month_dd.selectByVisibleText("Dec");
WebElement myElem = month_dd.getFirstSelectedOption();
System.out.println(myElem.getText());

  • 控制台输出:

  • Console Output:

    Dec
    PASSED: selectDDvalues
    
    ===============================================
        Default test
        Tests run: 1, Failures: 0, Skips: 0
    ===============================================
    

  • 这篇关于如何打印通过硒中的"selectByVisibleText"方法选择的所选选项的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆