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() doesn't 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();
Try getValue if it is a Text Field or Dropdown box
String lastname=selenium.getValue("//*[#id='lastName']");
System.out.println(lastname);
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)
Related
Here we know the Birimingam value. Based out of that value need to retrieve the text "BHM". Have indicated this in the image. How to retrieve hidden text which is "BHM" using Birimingham value xpath?
Try this xpath to access the element
//span[text()='Birmingham']/../../preceding-sibling::span/span
I want make automation for this web site
in this web site 3 text box are here check image
1st text box x path is /html[1]/body[1]/div[3]/div[1]/div[2]/div[1]/searchbar[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[1]/input[1]
here is my code
driver.findElement(By.xpath("/html[1]/body[1]/div[3]/div[1]/div[2]/div[1]/searchbar[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[1]/input[1]")).sendKeys("rio salon");
when I run this code I got this error
Exception in thread "main"
org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard
How can i fix it? I hope my xpath is correct.
The field has aria-hidden=true attribute, so you get ElementNotInteractableException. You need to click on the dropdown first to change the attribute to true
WebElement dropdown = driver.findElement(By.xpath("//*[#id='search-form']/div/div[1]/div/div[1]/span"));
dropdown.click();
WebElement textField = dropdown.findElement(By.xpath("./parent::div/following-sibling::input[contains(#class, 'ui-select-search')]"));
textField.sendKeys("rio salon");
You can click in an input field with a div or span tag, but you cannot type in the field. So, your XPath must be written with an input tag if you want to sendkeys or type in an input field. For example:
//input[contains(#placeholder,'Site')]
In y project i need to validate the textbox is string, textbox is data etc. Can some one help me in getting the value typed on the text box
You can get value from attribute 'value'.
string textInput = driver.FindElement(By.CssSelector("css-expression")).GetAttribute("value");
I need help with getting a Value posted from a form in VB.Net.
At the moment there is a form on a php website that is posting 2 values through to me.
name=Max
email=test"test.com
If i was using php i would use :
$name = $_POST['name'];
$email = $_POST['email'];
Now the above fields are now captured within a variable.
How do i do the the same thing in VB.NET
I cannot tell if you are referring to Web text box's or PHP forms but I can help you with Web text box's..
Your question is unclear, but I will try my best.
Assuming you want to get a textbox's value into a variable. You would do like so:
Example Textbox:
<asp:TextBox ID="ExampleTxtBox" runat="server" AutoPostBack="True"></asp:TextBox>
If you want to assign the values on a certain command, for example, a button click. You would put this into the button click handles of the button.
Assuming you want to get the current text/value from the form's text box:
Dim VariableOfTextBox As String 'Creates your Variable
VariableOfTextBox = ExampleTxtBox.text 'Assigns the Value from your Text Box
I have a Radcombobox in my application which has several check boxes in the combo box. What I wish to do is to fetch the text associated with the check box. I searched on internet and came to know that text can be fetched from name or value property in HTML code, but problem is that my HTML code does not have such properties.
HTML code:
input class="rcbCheckAllItemsCheckBox" type="checkbox"
Check All
What i wish to do is to fetch value "Check All".
Using code x = driver.findElement(By.xpath("/html/body/form/div[1]/div/div/div/input")).getText();, value returned is blank.
You can get the text through JavaScript API of Rad Controls. You can check the official documentation- http://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/client-side-programming/overview
Basically, you first locate the element in JS and then use the official control method, in your case get value method. You can also perform several other useful operations if you need to.
You can execute JS in WebDriver with the following code:
IWebDriver driver;
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
string title = (string)js.ExecuteScript("return document.title");