Problem
The problem with the line:
browser.execute_script("browser.find_element(:xpath,'/html/body/div[5]/div/div[3]/div[2]/div[2]/div/div/div/div/div/div/input'.disabled = false")
Is that it is trying to execute selenium-webdriver code instead javascript - ie browser.find_element
is not javascript.
Solution
Instead, do the following:
input_field = browser.find_element(:xpath, '/html/body/div[5]/div/div[3]/div[2]/div[2]/div/div/div/div/div/div/input')
browser.execute_script('arguments[0].removeAttribute("disabled");', input_field)
Note that:
- We can locate the element using selenium-webdriver and then pass that element for use in
execute_script
(as the arguments[0]
).
- To make a field no longer disabled, you actually need to remove the disabled attribute (rather than setting its value to false).
- You should be careful with using such an explicit xpath as it can be quite brittle - eg one small change will break it.