我在 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
但由于它的隐藏性质,它什么也不返回。
以下是源代码的片段。 突出显示的是感兴趣的字符串。 (值(value))
最佳答案
driver.switch_to_frame('undefined')
token_value = driver.find_element_by_id('recaptcha-token').get_attribute('value')
driver.switch_to_default_content()
关于python - 在 Selenium 中提取隐藏元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38417787/