Skip to main content
 首页 » 编程设计

python之我可以在 selenium 运行时最小化 chrome 窗口吗

2024年12月31日37mate10pro

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

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

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

会升高,或者有时 selenium 会停止。

找了好久有人说chrome窗口要聚焦不能通过点击窗口标题栏'-'最小化。替代解决方案是:

web.set_window_position(-2000,-2000)

让窗口移出屏幕。

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

我的问题是:

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

    set_window_position(-2000,-2000)

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

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

环境:

  • python 3.6
  • Chrome 66.0
  • Selenium 3.11.0
  • Windows 服务器 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) 

请您参考如下方法:

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