How to get entered text from a textbox in selenium

前端 未结 3 1702
余生分开走
余生分开走 2021-02-01 03:09

I enter a value in TextBox or a Combobox, and would like to retrieve the value I have just entered. I see that Selenium Weblement method \'getText()\' doesnt retrieve the value,

相关标签:
3条回答
  • 2021-02-01 03:46

    Try getValue if it is a Text Field or Dropdown box

    String lastname=selenium.getValue("//*[@id='lastName']");
    System.out.println(lastname);
    
    0 讨论(0)
  • 2021-02-01 03:56

    The getText() method is for retrieving a text node between element tags for example:

    <p>Something</p>
    

    getText() will return "Something"

    In a textbox typed text goes into the value attribute so you can try something like:

    findElement(By.id("someid")).getAttribute("value");
    

    ComboBox is a bit different. But if you're using the Select object you can use the method:

    Select selectItem = new Select(findElement(By.id("someid")));
    selectItem.getFirstSelectedOption().getText();
    
    0 讨论(0)
  • 2021-02-01 04:07

    This is how we can fetch the text written in a textbox using Selenium + Python:

    text = driver.find_element_by_xpath("Type_Xpath_Here").get_attribute('value')
    print(text)
    
    0 讨论(0)
提交回复
热议问题