How to get entered text from a textbox in selenium

孤街醉人 提交于 2019-12-20 09:12:00

问题


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, it seems the entered text doesn't get pushed into DOM.

Any Solutions ?


回答1:


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();



回答2:


Try getValue if it is a Text Field or Dropdown box

String lastname=selenium.getValue("//*[@id='lastName']");
System.out.println(lastname);


来源:https://stackoverflow.com/questions/13990566/how-to-get-entered-text-from-a-textbox-in-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!