Can I minimize chrome window while selenium is run

2020-04-12 12:55发布

I have a project to get some information from website. I want to look at the process inside the chrome window, So I can't use headless browser. But sometimes I want to minimize the chrome window.

But I found the selenium would go wrong after I minimize the chrome window manually, but sometimes not. When go wrong, exception

element is not clickable at the point, other element will receive the click

will be raised, or sometimes selenium just stop.

I have searched for a long time that some people said that the chrome window should be focused on and can't be minimized by clicking '-' on the window title bar. And the alternative solution is:

web.set_window_position(-2000,-2000)

To make the window move out the screen.

And someone says by simulating shortcuts to minimize the window. But I think it's the same as click '-' manually, am I wrong?

My question is :

  • Does selenium really requires chrome window not minimized? Why sometimes it can run selenium normally after minimized but sometimes not?
  • If I use

    set_window_position(-2000,-2000)

    to move the window invisible, then I click the window icon on the bottom of os (I'm sorry that I don't know what it's called). Normally when clicked, the window will be minimized. So as for this chrome window, Will it be considered as minimized window and go wrong?

I am really sorry for my poor English. I hope I have a clear description of my problem.

Environment:

  • python 3.6
  • chrome 66.0
  • selenium 3.11.0
  • windows server 2012

Edit to add code:

wait.WebDriverWait(driver,100000).until(EC.visibility_of_element_located((By.ID,'commMgrCompositionMessage')))
        textArea = driver.find_element_by_id('commMgrCompositionMessage')
        driver.execute_script("arguments[0].value="+"'"+modelStr+"';",textArea)
        time.sleep(1)
        wait.WebDriverWait(driver,10000).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,'#sendemail_label')))
        allSendMailLabel = driver.find_elements_by_css_selector('#sendemail')
        allSendMailLabel = allSendMailLabel[1]
        driver.execute_script("arguments[0].click();", allSendMailLabel)

1条回答
家丑人穷心不美
2楼-- · 2020-04-12 13:39

If you see the question here Debugging "Element is not clickable at point" error, there is a bug in the chromedriver that causes this. The issue for it was created here. There is a workaround listed in the 27th comment, but what you can do is switch to the firefox driver and see if that works. Minimised windows should not cause a problem otherwise.

查看更多
登录 后发表回答