I am trying to get value from a text field using selenium, but I am not able to. The value is neither present between the tags nor in the attribute "value".Please help me with this.
I have tried following ways but nothing worked.
Webelement.getAttribute("innerText");
Webelement.gettext();
Webelement.getAttribute("value");
Webelement.getAttribute("textcontent");
Below is the HTML for the text field.
<input name="quantityField_valueFieldKeyboard" id="quantityField_valueFieldKeyboard" data-mini="true" data-clear-btn="false" maxlength="61" seyctype="numeric" class="seyc-visually-important seyc-ui-input-icon-white seyc-ui-input-text">
is this what you are trying?
driver.findElement(By.id("quantityField_valueFieldKeyboard")).getAttribute("value");
driver.findElement(By.id("quantityField_valueFieldKeyboard")).getAttribute("value");
is correct way. You are getting empty string is also correct because your text field has no data in it. Since this is an input field, first enter some text and once text is saved. Try to fetch the entered text you will get your desired results.
Related
I have a webpage where some elements get set on page load. I then need to read some of these elements using Selenium. The problem is that when I read them, all I get is an empty string.
This is a partial image of my website:
I'm trying to obtain the Number field.
Here is what the DOM looks like for this element:
<input style="; ; " class="form-control disabled " id="sys_readonly.u_po_coordination.number" value="POI1356285" ng-non-bindable="" readonly="readonly" aria-label="Number">
Here is my JAVA code to get that value:
String num = driver.findElement(By.id("sys_readonly.u_po_coordination.number")).getText();
I've tried using XPath as well. I've also tried getting other elements as well.
The result is ALWAYS the same: a blank string...
What am I missing? The elements exist because I can set various elements, but reading ones that should be set are always blank.
Any help would be greatly appreciated.
Thanks!
driver.findElement(By.id("sys_readonly.u_po_coordination.number")).getAttribute("value");
Found this website which was pretty useful:
https://www.lambdatest.com/blog/how-to-get-text-of-an-element-in-selenium/
Instead of getText() can you try getValue()?
I want to validate a text but its in Hindi in the website i am working on .
The code goes this way
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.textToBePresentInElementLocated(
By.xpath("/html/body/nav[1]/div/ul/div/div/li[2]/form/input[4]"),
"हिंदी"));
System.out.println("Language changed to "+ landingpage.getHindiLanguage().getText());
And The Output I Get is
Expected condition failed: waiting for text ('?????') to be present in element found by By.xpath:
How shall i approach this?
From your xpath assuming you are trying to getText from a input tag
Input tag stores the value in value attribute so you should get the value from the attribute instead of using getText() use
webelement.getAttribute("value") this will return values stored in input field
getText() will works only for HTML element which store values in node.
Like p tag as shown below
<p>PARAGRAPH</p>
I wants to verify value that is present in Display Name field.
After entering First Name Display Name will populates automatically.
display name value is present in front-end but not present in DOM.
I tried with
driver.webdriver.findElement(By.id("DisplayName")).getText();
and
String abc= driver.webdriver.findElement(By.id("DisplayName")).getAttribute("value");
driver.findElement(By.xpath(".//*[#id='DisplayName']")).getAttribute("value");
Hi this works for me...
I'm trying to verify the tool tip text using selenium for the following HTML code.But not sure how to proceed further.
HTML CODE:
<div id="divImgAnnualAllowanceType" class="imgHelp" _tooltip="If the client
<br>an arrangement
<br>a durable arrangement
<br>received a Lump Sum.">
</div>
Since the text is separated by <br> I don't know how to retrieve this text.
I tried using the following code but got null value.
driver.findElement(By.id("divImgAnnualAllowanceType")).getAttribute("value");
Thanks in Advance :)
<div> tags doesn't (necessarily) has value attribute, use getText() instead
driver.findElement(By.id("divImgAnnualAllowanceType")).getText();
You should specify the attribute which value you need.
driver.findElement(By.id("divImgAnnualAllowanceType")).getAttribute("_tooltip");
You have to use proper attribute name with getAttribute() method and there is no attribute as value in your targeted <div> element, you can try below code:
String tooltip = driver.findElement(By.id("divImgAnnualAllowanceType")).getAttribute("_tooltip");
System.out.println(tooltip.replace("<br>", ""));
In above code, we are storing the tooltip value in a variable then printing the same after replacing all <br>.
This code is written in Java.
How to get translate text value from an Angular tag using selenium Java. Specifically saying, I want the value coming in translate tag
<h5 id="myModalLabel" class="modal-title">
<span translate="EMAIL_MSG"/>
Please enter your email address. </h5>
The translate tag is returning value "An email with instructions to reset your password will be sent to test.test#test.com . Please check your email shortly."
translate is an attribute, not a tag. Use getAttribute() method to get the value
String value = driver.findElement(By.cssSelector("#myModalLabel > span")).getAttribute("translate");
Not sure what are you asking here by getting translate text value. Did you try simply using getText()?
This should simply return you the text you need.
driver.findElement(By.xpath("//*[#id='myModalLabel']/span")).getText();