1

My html code is -

    <input id="txtPortalLogin" class="form-control input-sm" type="text" disabled="disabled" placeholder="No Link" value=""/>

Please assist some code to get the values from disabled field. Screenshot is attached so that you will find the which text values i am talking about. Input Fields are disabled and I want values from shown screenshot

Sumant K
  • 11
  • 1
  • 2
  • 1
    http://stackoverflow.com/questions/11429070/selenium-wd-get-value-of-disabled-input go to this link and u will get details. – noor Dec 08 '15 at 09:11

4 Answers4

0

I know how to get this value with Python code:

from selenium import webdriver
driver = webdriver.Firefox()
driver.get('your_page_url')
disabled_input_field = driver.find_element_by_id("txtPortalLogin")
value = disabled_input_field.get_attribute('value')
Andersson
  • 51,635
  • 17
  • 77
  • 129
0

Use the javascript executor in selenium to execute a javascript code which return the value of the html element ( input). Something simmilar to the below

 String value = "";
if (driver instanceof JavascriptExecutor) {
    String value = (String)((JavascriptExecutor) driver)
        .executeScript("return document.getElementById('txtPortalLogin').value");
}
Alan M
  • 616
  • 5
  • 15
0

In C# it would be

driver.FindElement(By.Id("txtPortalLogin")).GetAttribute("value");

however you could also do this using the JavaScript executor as so:

var value = ((IJavascriptExecutor)driver).ExecuteScript("return $('#txtPortalLogin').attr('value')").ToString();

EDIT; I think the OP might want to get the https://production etc part out of the field. I'm not 100% sure how to do that, sorry.

I did also find this link which might be able to answer your problem; TLDR is make it readonly instead of disabled which allows the value behind to still be accessible but not changeable by the user.

Community
  • 1
  • 1
Dillanm
  • 876
  • 12
  • 28
  • There is a shorter way $('#txtPortalLogin').val(); however that is jQuery not a clear javascript – dmr Dec 08 '15 at 23:46
  • OP didn't specify that it had to be pure JavaScript. This is pure speculation and probably an error on my part as I am not a JavaScript dev, but is JQuery not fairly common if not a staple of most sites? – Dillanm Dec 14 '15 at 15:48
0

Usually driver.getAtribute("value"); works. But as value field is empty, you'll have to go for JavaScriptExecutor -

JavascriptExecutor je = (JavascriptExecutor) webDriver;

String value = je.executeScript("return angular.element(arguments[0]).scope().{{modalValue:put modal value from HTML}};", {{webElement}}).toString();

return value;
Sampada
  • 2,931
  • 7
  • 27
  • 39
NDP
  • 22
  • 4