ElementNotVisibleException when use headless Chrome browser

后端 未结 4 2454
慢半拍i
慢半拍i 2021-02-20 02:25

When I run test script in headless mode chrome browser, element link is not visible, is not able to do linkElement.click(). in head mode is everything OK. All other

4条回答
  •  猫巷女王i
    2021-02-20 03:02

    I think the problem is, that the Element is really not visible in the default viewbox (600x800) of Headless Chrome.

    The window size of the Headless Browser must be set as a Argument when starting chrome. I'm using javascript (I think the API looks similar under python):

    var Options = require('selenium-webdriver/chrome').Options;
    var options = new Options();
    options.addArguments('headless');
    options.addArguments('disable-gpu');
    options.addArguments('window-size=1200,1100');
    
    browser = builder.forBrowser('chrome').setChromeOptions(options).build();
    

    Additional Info

    I'm setup up the window size also by webdriver with browser.manage().window().setSize(1200,1100); But this command is not sufficient in headless chrome. In the non headless variant this is working.

提交回复
热议问题