java – Selenium getText

I want to use by ID or by cssSelector getText().

I try to solve my problem by executing getattribute ("value"), but I don't understand why gettext () doesn't work as I expected. I may need it, so all the help is appreciated

This is Java:

webdriverwait wait = new webdriverwait(driver,10);         
Boolean elementIsPresent = wait.until(ExpectedConditions.textToBePresentInElementValue(By.cssSelector("#general_service_name"),"[reg] general_service_name")); // true          

//WebElement general_service_name = driver.findElement(By.cssSelector("#general_service_name"));
WebElement general_service_name = driver.findElement(By.id("general_service_name"));

// Display check
Boolean isDisplayed;
if(general_service_name.isDisplayed())  isDisplayed = new Boolean(true); else isDisplayed = false; //true

String text_empty = general_service_name.getText(); //""
String text_with_value = driver.findElement(By.id("general_service_name")).getAttribute("value"); //"[reg] general_service_name"

And HTML:

<input id="general_service_name" type="text" value="[reg] title" name="general_service_name" style="float:left;"/>

Solution

http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html#getText ()

Gettext() provides innerText. Of webelement

Your input field does not have any internal text The text is in value attribute, so it is the right way to access it through getattribute ("value")

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>