1

HTML:

<textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" 
style="width: 250px; height: 40px; border: 1px solid rgb(193, 193, 193); margin: 10px 25px; padding: 
0px; resize: none; display: none;"></textarea>

i'm trying to remove the "display: none" attribute, how would I go about doing this in the python version of selenium?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Sean A
  • 11
  • 2

4 Answers4

1

Just set it to block to make it visible.

driver.execute_script("arguments[0].style.display = 'block';",elem)

Removing would be below where elem is your webelement.

driver.execute_script("arguments[0].removeAttribute('style')",elem)
Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32
1

You can make the display box to input the reCaptcha key visible by replacing the display attribute with pretty much anything!

You can do this:

driver = webdriver.Chrome()
element = driver.find_element_by_id('g-recaptcha-response')
driver.execute_script("arguments[0].setAttribute('style', 'display: true')", element)
Isukali
  • 109
  • 12
0

You can do as per below 2 methods

String visibility = web.findElement(By.xpath("//your xpath")).getCssValue("display");

You will get display value and then you can remove it. other way to do it using below code.

firefox = webdriver.Firefox()
element = firefox.find_element_by_css_selector("this element css selector here")
attributeValue = element.get_attribute("style")

Style element you will get and remove display from it.

Akash senta
  • 483
  • 7
  • 16
0

To remove the style attribute containing display: none; you need to use removeAttribute() inducing WebDriverWait for the presence_of_element_located() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.execute_script("arguments[0].removeAttribute('style')", WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, "textarea.g-recaptcha-response#g-recaptcha-response[name='g-recaptcha-response']"))))
    
  • Using XPATH:

    driver.execute_script("arguments[0].removeAttribute('style')", WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//textarea[@class='g-recaptcha-response' and @id='g-recaptcha-response'][@name='g-recaptcha-response']"))))
    

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352