Chromeheadless抛出空白页作为URL重定向中的屏幕截图

时间:2018-11-15 07:29:02

标签: python selenium selenium-webdriver selenium-chromedriver

我已经用python硒编写了代码,并且在没有chromeheadless的情况下代码可以正常工作。使用无色头的第一部分登录时(请参见下面的代码)可以正常工作

def login():
     myProxy = "ipaddress:8080"
     chrome_options = webdriver.ChromeOptions()

     chrome_options.add_argument('--headless')
     chrome_options.add_argument('--proxy-server=%s' % myProxy )
     driver= webdriver.Chrome(executable_path=
     'C:\\Scripts\\test\\driver\\chromedriver', 
     chrome_options=chrome_options, 
     service_args=["--verbose", "--log- 
     path=C:\\Scripts\\qc1.log"])

     driver.get("http://apps.cloudhealthtech.com/dashboard")
     driver.find_element_by_tag_name('button').send_keys(Keys.ENTER)
     driver.find_element_by_id('email_input').send_keys("emailid")
     driver.find_element_by_id('login_button').send_keys(Keys.ENTER)
     driver.get_screenshot_as_file("capture.png")

直到上面的部分都可以正常工作,但是在此网址重定向后进行单点登录,并且下面的代码不起作用。

time.sleep(5)

keyboard.press_and_release('tab')
keyboard.press_and_release('shift + tab')  
time.sleep(2)  
keyboard.write("username", delay=1)
time.sleep(5)
keyboard.press_and_release('tab')
time.sleep(5)
keyboard.write("password", delay=1)
time.sleep(2)
keyboard.press_and_release('enter')

它应该在弹出窗口中输入用户名和密码,但在快照中显示空白页面

请参阅以下日志错误

1542283010.243][DEBUG]: DevTools WebSocket Event: Log.entryAdded 0C8ED5D1D48339211778F73D59D23A89 {
   "entry": {
      "level": "error",
      "networkRequestId": "CE55C95230B89FC3D3783AD07E45779C",
      "source": "network",
      "text": "Failed to load resource: the server responded with a status of 401 (Unauthorized)",
      "timestamp": 1542283010238.73,

0 个答案:

没有答案