ElementNotVisibleException when using a Chrome browser without a browser

When I run a test script in a Chrome browser without a browser, the link to the item is not displayed, it cannot execute linkElement.click(). in head mode, everything is fine. All other data is in stacktrace. Does anyone know what to do, please?

Stacktrace:

An error has occurred: message: the item is not displayed
 (Session information: headless chrome = 60.0.3112.90)
  ( Driver information: chromedriver = 2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8), platform = Windows NT 6.1.7601 SP1 x86_64)
Traceback (last call) :
  File "C: \ nik-x.py", line 148, FUNC (Nik) main page
  File "C: \ lib \ support.py", line 121, in the wrapper
    raise ret
  File "C: \ lib \ support. py ", line 108, in newFunc
    res [0] = func (* args, ** kwargs)
  File" C: \ testcases \ nik-1003.py ", line 37, in the
    i.click () test file
  File" C : \ Python36 \ lib \ site-packages \ selenium \ webdriver \ remote \ webelement.py ",line 7
7, click click self._execute (Command.CLICK_ELEMENT)
  file "C: \ Python36 \ lib \ site-packages \ selenium \ webdriver \ remote \ webelement.py", line 4
93, in _execute return self._parent.execute (command , parameters)
  File "C: \ Python36 \ lib \ site-packages \ selenium \ webdriver \ remote \ webdriver.py", line
25-6, executed by self.error_handler.check_response (answer)
  File "C: \ Python36 \ lib \ site-packages \ selenium \ webdriver \ remote \ errorhandler.py ", line
 194, in check_response
    raise exception_class (message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: item not displayed
  (Session information: headless chrome = 60.0.3112.90)
  (Driver information: chromedriver = 2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8), platform = Windows NT 6.1.7601 SP1 x86_64)

Here is my piece of code:
 icons = nik.elementLeftmenuSportIcons() for i in icons[:-1]: try: i.click()

HTML from the test page: <a href="#" class="default b_futbal gaPageEventElement" data-ga-cat="Sporty" data-ga-action="futbal"> <span class="left-menu-only-large-res">Futbal</span> </a>

+10
source share
4 answers

I think the problem is that the item doesn’t really appear in the default viewport (600x800) of Chrome headless.

The headless browser window size should be set as an argument when starting chrome. I am using javascript (I think the API is similar to 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 Information

webdriver browser.manage().window().setSize(1200,1100); . .

+10

, .

1. Chrome, ( ):

ChromeOptions options = new ChromeOptions()
options.addArguments("headless");
options.addArguments("window-size=1200,1100");
WebDriver driver = new ChromeDriver(options);

2. Chrome:

WebDriver webDriver= new ChromeDriver();
webDriver.manage().window().setSize(new Dimension(1200,1100));
+1

options.addArguments( ' = 1200,1100');

:) @powerpete

groovy: -

        ChromeOptions options = new ChromeOptions()
        DesiredCapabilities capabilities = DesiredCapabilities.chrome()
        options.addArguments('headless','disable-gpu','--test-type','--ignore-certificate-errors')
        options.addArguments('window-size=1200,1100');
        capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capabilities.setCapability(ChromeOptions.CAPABILITY, options)
        driver = {new ChromeDriver(capabilities)}
0

, , , HTML .

, FireFox, Chrome. Xpath Chrome . , HTML Chrome.

, Xpath Chrome Xpath FireFox Chrome.

0

Source: https://habr.com/ru/post/1683222/


All Articles