我需要在表单提交后得到响应页面,但我有空表单域的同一页面。我正在尝试使用time.sleep()
,但它没有帮助。如何在seh验证后获取响应页面?
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
phantom_js_executable_path = './bin/phantomjs.exe'
user_agent = (
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.37 (KHTML, like Gecko) Chrome/54.0.2705.89 Safari/536.37"
)
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = user_agent
def main():
driver = webdriver.PhantomJS(executable_path = phantom_js_executable_path) # or add to your PATH
driver.get('http://any.syte.my/login')
user_name = driver.find_element_by_id("username")
user_name.send_keys("user")
password = driver.find_element_by_id("password")
password.send_keys("pass")
driver.find_element_by_name('continue').click()#form button submit
#time.sleep(10)
driver.save_screenshot('screen.png') # save a screenshot to disk
if __name__ == '__main__':
main()
'http:// somedomain/url_that_delays_loading'是它成功认证后允许我的url吗? – Someone
这只是一个例子。您应该在'尝试'块之后使用该部分。因此,您必须用成功验证后获得的页面中显示的元素ID替换'driver'和'myDynamicElement'的'ff'。 –
我替换它,我的代码如下所示:https://ghostbin.com/paste/qq9xz但它不起作用。 – Someone