我可以在 Selenium 运行时最小化 chrome 窗口吗?

Yan*_* Li 5 python selenium google-chrome

我有一个项目要从网站获取一些信息。我想查看chrome窗口内的进程,所以我不能使用无头浏览器。但有时我想最小化镀铬窗口。

但是我发现手动最小化chrome窗口后selenium会出错,但有时不会。当出错时,异常

元素在该点不可点击,其他元素将收到点击

会提高,或者有时硒就停止。

搜索了很久有人说chrome窗口应该聚焦,不能通过点击窗口标题栏的“-”来最小化。替代解决方案是:

web.set_window_position(-2000,-2000)

使窗口移出屏幕。

还有人说通过模拟快捷键来最小化窗口。但我认为这和手动点击“-”是一样的,我错了吗?

我的问题是:

  • Selenium 真的需要 chrome 窗口不最小化吗?为什么最小化后有时可以正常运行selenium有时却不能?
  • 如果我使用

    设置窗口位置(-2000,-2000)

    要将窗口移动为不可见,然后我单击操作系统底部的窗口图标(很抱歉,我不知道它叫什么)。通常,单击时,窗口将最小化。那么对于这个chrome窗口,它会被认为是最小化窗口而出错吗?

我真的很抱歉我糟糕的英语。我希望我能清楚地描述我的问题。

环境:

  • 蟒蛇3.6
  • 铬66.0
  • 硒3.11.0
  • 视窗服务器 2012

编辑添加代码:

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)
Run Code Online (Sandbox Code Playgroud)

ytp*_*lai 2

如果您在此处看到问题Debugging "Element is not clickable at point" error,则 chromedriver 中存在导致此问题的错误。它的问题是在这里创建的。第 27 条评论中列出了一个解决方法,但您可以做的是切换到 Firefox 驱动程序,看看是否有效。否则,最小化窗口不会引起问题。