Thomas Dukes Thomas Dukes - 4 months ago 37
HTML Question

Extracting hidden element in Selenium

I have an element of type

hidden
in an iframe. I am wondering if there would be any way to get this value as I am using selenium. More specifically it is a captcha field. I've tried pulling it with something along the lines of

#!/usr/bin/env python

from selenium import webdriver
driver=webdriver.Chrome(chrome_bin_path)
driver.get('http://websitehere.com')
print driver.find_element_by_xpath('//*[@id="recaptcha-token"]').text


but because of it's hidden nature it returns nothing.

Below is a snippet of the source.
Highlighted is the string of interest. (value)

source

Answer
driver.switch_to_frame('undefined')
token_value = driver.find_element_by_id('recaptcha-token').get_attribute('value')
driver.switch_to_default_content()

Moving between windows and frames.

Comments