Reputation: 184
I have been trying to read the text from a textbox which is a class place holder as you can see below
UPDATE:
<div id="annotationHistoryDataTable_filter" class="dataTables_filter">
<label>Search:<input type="search" class="" placeholder="" aria-
controls="annotationHistoryDataTable">
</label></div>
I am using the below code to get the text but i am getting a null value. This usually gets all the text but is not working for this kind of text box.
var theseElements = driver.FindElement(By.TagName("annotationHistoryDataTable")).Text;
Tried with By.LinkText too but still not working.
Here is the example of the textbox i want to read
Thank you.
Upvotes: 0
Views: 845
Reputation: 19939
var theseElements = driver.FindElement(By.TagName("annotationHistoryDataTable")).Text;
var theseElements = driver.FindElement(By.XPATH("//input[@aria-controls=\"annotationHistoryDataTable\" and @type = \"search\"]"));
Now try ;
theseElements.text
theseElements.getAttribute('value')
so as elements are inside iframe you need to switch to it first
driver.SwitchTo().Frame(driver.FindElement(By.XPATH("iframexpath")));
var theseElements = driver.FindElement(By.XPATH("//input[@aria-controls=\"annotationHistoryDataTable\" and @type = \"search\"]"));
theseElements.getAttribute('value') //print this
If you want to interact with elements outside the iframe after this , then you have to switch outside of iframe;
driver.SwitchTo().DefaultContent(); // just add this line after you are done with interacting with iframe elements
Upvotes: 1
Reputation: 25048
You try to get that input
by driver.FindElement(By.TagName("annotationHistoryDataTable")).Text;
Ask yourself: Is there a TagName annotationHistoryDataTable
?
input
?It is an input
and it has an aria-controls
, use this in your xpath
:
driver.FindElement(By.XPATH("//input[@aria-controls='annotationHistoryDataTable']"))
The text
is not stored between the <input>
it is stored in the value
attribute, so you should access it like:
.GetAttribute("value")
Example
It is in python, but should show you what I mean.
from selenium import webdriver
browser = webdriver.Chrome('C:\Program Files\ChromeDriver\chromedriver.exe')
html_content = """
<label>
Search:<input type="search" class="" placeholder="" aria-controls="annotationHistoryDataTable">
</label>
"""
browser.get("data:text/html;charset=utf-8,{html_content}".format(html_content=html_content))
browser.find_element_by_xpath("//input[@aria-controls='annotationHistoryDataTable']").get_attribute("value")
browser.close()
Upvotes: 1
Reputation: 196
You should try this :
var theseElements = driver.FindElement(By.TagName("annotationHistoryDataTable")).get_attribute("innerText");
Upvotes: 1