【问题标题】:Extracting hidden element in Selenium在 Selenium 中提取隐藏元素
【发布时间】:2016-11-19 22:38:42
【问题描述】:

我在 iframe 中有一个 hidden 类型的元素。我想知道在我使用硒时是否有任何方法可以获得这个值。更具体地说,它是一个验证码字段。我试过用

的方式来拉动它
#!/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

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

下面是源码的sn-p。 突出显示的是感兴趣的字符串。 (价值)

【问题讨论】:

  • 你可以看看this的问题。也许它可以帮助你。

标签: python html selenium captcha recaptcha


【解决方案1】:
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.

【讨论】:

  • 作为奖励,您知道我是否可以在验证码解决后重复该步骤吗?解决后,以类似方式在#document 内出现一个具有匹配 id 的新标签。
【解决方案2】:

使用这个方法

hidden_text = element.get_attribute("textContent")

【讨论】:

    猜你喜欢
    • 2017-04-16
    • 2012-08-15
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-29
    相关资源
    最近更新 更多