【问题标题】:Get selected value from drop down selenium python从下拉 selenium python 中获取选定的值
【发布时间】:2019-09-27 10:32:43
【问题描述】:

我是硒新手 做出选择后,我想从下拉按钮中获取选定的选项值 在这里我尝试了一些东西,但我没有得到预期的结果

exams=Select(driver.find_element_by_id("exam"))
option1=exams.first_selected_option
print("option 1    ->   ",option1)

输出是

option 1 -> <selenium.webdriver.remote.webelement.WebElement (session="caa3498bece769cdcc9db1143e54c516", element="18ba0158-5c50-4d67-88e4-466bc6dacc67")>

在java中getText()用于获取值。 python中有没有类似的方法

【问题讨论】:

    标签: python-3.x selenium selenium-webdriver text webdriver


    【解决方案1】:

    您需要打印 WebElementtext 属性,而不是打印 WebElement option1

    如此有效地你需要替换:

    print("option 1    ->   ",option1)
    

    与:

    print("option 1    ->   ",option1.text)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-10
      • 2019-03-07
      • 2015-09-23
      相关资源
      最近更新 更多