How to get the value from <input> tag using java in Selenium web driver when the Value attribute is generated dynamically
selenium, selenium-webdriver
Solution
To select the input value you'll need to use an xpath selector as using `by.id` will find the select element as they share the same `id` - which is bad practice as they really should be unique. Anyway, try:
driver.findElement(By.xpath("//input[@id='GlobalDateTimeText']")).getAttribute("value");
Problem
The HTML I am trying to operate on: ``` <select id="GlobalDateTimeDropDown" class="combo" onchange="CalculateGlobalDateTime('Time',this.value)" name="GlobalDateTimeDropDown"> <option value="+5.5" selected="selected"> … </option> <option value="+12"> … </option> <option value="+8"> … </option> <option value="+2"> … </option> </select> <input id="GlobalDateTimeText" class="combo" type="text" name="GlobalDateTimeText" value="" style="width:215px;padding:2px;" readonly="readonly"></input> ``` Java Code: ``` WebElement values=driver.findElement(By.id("GlobalDateTimeText")).getAttribute("Value"); System.out.println(values); ``` Output: Blank