2016-07-17 34 views
0

我在iframe中有一个hidden类型的元素。我想知道是否有任何方法可以得到这个值,因为我使用硒。更具体地说,它是一个验证码字段。我试过用一些东西拉它在Selenium中提取隐藏元素

#!/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 

但由于它的隐藏性质,它什么都不返回。

以下是源代码片段。 突出显示的是感兴趣的字符串。 (值)

source

+0

您可能需要查看[this](http://stackoverflow.com/questions/18500711/read-a-hidden-value-in-a-div-using-selenium-python-binding)问题。也许它可以帮助你。 – dazzieta

回答

2
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

+0

作为奖励,您是否知道在验证码解决后是否可以重复此步骤?解决之后,一个新的标签以类似的方式出现在#document内部。 –