0

How to set value in hidden textbox using selenium java. It throws the following error, "Element must not be hidden, disabled or read-only...". I tried many methods like using sendkeys, using js excute but nothing works out. Please refer the following code in my script,

Method:1

driver.findElement(By.xpath("editbox")).sendKeys(input);

Method:2

driver.findElement(By.id("editbox")).setAttribute("value", "your value");

Method 3:

WebElement Element = driver.findElement(By.id("editbox"))
js.executeScript("arguments[0].value = arguments[1];", Element, input);
Ismail
  • 79
  • 2
  • 13
  • Did you try to make it visible? – Andersson Mar 10 '18 at 11:46
  • Hi @Andersson, I'm new to selenium. Can you please tell me how to make it visible – Ismail Mar 10 '18 at 11:59
  • You can wait for [visibility of element](https://stackoverflow.com/questions/10941184/equivalent-of-waitforvisible-waitforelementpresent-in-selenium-webdriver-tests-u) or [scroll down](https://stackoverflow.com/questions/3401343/scroll-element-into-view-with-selenium) to make it visible – Andersson Mar 10 '18 at 12:10
  • @Andersson, I tried this. It shows that the object is visible. Click using js is working in that object but there is problem only with 'set' – Ismail Mar 10 '18 at 12:16
  • Update the question with the relevant _HTML_ and the exact _Manual Steps_ which you are trying to _Automate_. – undetected Selenium Mar 10 '18 at 14:23
  • @DebanjanB I need to set value in an edit box. The edit box HTML structure is,
    ...
    – Ismail Mar 10 '18 at 15:45

2 Answers2

0

The quick way of doing this is by using js, this is an answer using python with selenium:

    # Test that captcha response field is in the page
    captcha_response = driver.find_element_by_id(LocatorsFirstPage.FORM_CAPTCHA_RESPONSE_ID)


    # Make captcha response visible to input response
    driver.execute_script('var element=document.getElementById("g-recaptcha-response"); element.style.display="";')

    # Set captcha response
    driver.execute_script('document.getElementById("g-recaptcha-response").innerHTML = arguments[0]', result)
    driver.find_element_by_id("g-recaptcha-response").innerHTML=result

    print(captcha_response.get_attribute("value"))

Then you can make it not visible by setting the style to "display: none;" the same way using js.

-1

Is your invisible element going to be visible at some point or is permanently invisible? If the element is visible after some time, you can wait to it's visibility:

wait.until(ExpectedConditions.visibilityofelement(by.id(...
slfan
  • 8,950
  • 115
  • 65
  • 78
pburgr
  • 1,722
  • 1
  • 11
  • 26