wretnuh
wretnuh

Reputation: 23

How to change innerHTML with python in a selenium firefox window?

I am trying to enter a string of characters into a hidden text area on the page that is opened with selenium firefox. I have gotten it to return the html, but have not been able to figure out how to edit the html, like I am able to do when inspecting element. I am very new to coding, so please excuse how ignorant I may sound.

this is the html that i am trying to type into:

<textarea id = "xxx"
          name = "xxx"
          class = "xxx"
          style = "border  : 1px solid #c1c1c1;
                   display : none;
                   height  : 40px;
                   margin  : 10px 25px;
                   padding : 0px;
                   resize  : none;
                   width   : 250px;">
</textarea>

I understand that I want to enter needs to be input between the two > <, but I do not know how to 1. input text there using python, and 2. if the text i input there will be there if that textarea is still set to display : none.

Upvotes: 2

Views: 3331

Answers (1)

Akarsh
Akarsh

Reputation: 967

If you want to make this text area to be visible, you need to make 'display:none' to 'display:block' using execute script like below. After that you can send text using sendkeys.

driver = webdriver.Firefox()
driver.implicitly_wait(20)
driver.get("Url of your page")
driver.maximize_window()
driver.execute_script("document.getElementById('xxx').style.display = 'block';")
driver.find_element_by_id("xxx").send_keys("test")

Let me know if you have any queries

Upvotes: 3

Related Questions