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
Related
A problem derived from my previous question:" VBA to find if an element contains certain texts"
I find the desired text using :
driver.FindElementByXPath("//*[#class='x-grid3-cell-inner' and text()='TEXT']")
but it is unclickable. The box in the next column is where i want to click.
How to click a nearby grid column ?
Ca72-4 is what i try to find.
The grid row of Ca72-4 may differ.
Path of the text (in selenium) :
xpath=//div[42]/table/tbody/tr/td[3]/div
The yellow box on the right is input.
Path of the desired target (in selenium) :
xpath=//div[42]/table/tbody/tr/td[4]/div
Thank you for your help.
To click() in the adjascent cell next to the text Ca72-4 you can use the following xpath based Locator Strategy:
driver.FindElementByXPath("//div[#class='x-grid3-cell-inner' and text()='Ca72-4']//following::td[1]/div").Click
A solution may be to dim an integer and to loop and check all div[#] and then use the integer with targets xpath. But i'd really like to avoid loops if possible.
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')]
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");
I have a page containing multiple forms with their own submit buttons and other elements. While testing the page, I locate the second form
WebElement form = getDriver().findElement(By.id("form2"));
and then field and submit button
form.findElement(By.name("text")).sendKeys("Adding some text here");
form.findElement(By.xpath("//input[#type='submit']")).click();
However these xpath locations take effect on the first form. Is it really so that the xpath doesn't work inside a specified element?
Try a relative path:
form.findElement(By.xpath(".//input[#type='submit']")).click();
In fact Selenium works with the first found by xpath element. If you know exact order number you can add such a number to your xpath //input[#type='submit'][2]. Please note that numbering in xpath starts from 1 but not 0. So given xpath will found for you the second input with #type='submit'.
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)