如何从硒文本框中输入文本 [英] How to get entered text from a textbox in selenium
问题描述
我在文本框或组合框中输入一个值,并想要检索刚才输入的值。我看到Selenium Weblement方法'getText()'不检索值,似乎输入的文本不会被推送到DOM。
任何解决方案?
getText()
方法用于检索元素标记之间的文本节点例如: < p>东西< / p>
getText()
将返回Something
在文本框中键入文本会进入value属性,因此您可以尝试如下所示:
findElement(By.id( someid))的getAttribute( 值)。
ComboBox
有点不同。但是如果您使用选择
对象,则可以使用以下方法:
Select selectItem = new Select(findElement(By.id(someid)));
selectItem.getFirstSelectedOption()。getText();
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 ?
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();
这篇关于如何从硒文本框中输入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!