ElhamMn
ElhamMn

Reputation: 39

Problem with Headless when running selenium test using java

I have a problem with running a test in headless mode. I wrote my test cases in two different (web shop and portal). Likewise, I am using Headless, my test works when headless is true in web-shop, but they don't work when headless is true in portal test cases.

org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element is not clickable at point (480, 483). Other element would receive the click: ... (Session info: headless chrome=91.0.4472.114) Build info: version: '4.0.0-beta-3', revision: '5d108f9a67' System info: host: 'moin-mkt-007.local', ip: 'fe80:0:0:0:1412:539b:3727:1402%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '14.0.2' Driver info: org.openqa.selenium.chrome.ChromeDriver Command: [d05ff1a9794fef32216ef34021b22337, clickElement {id=de6be461-9b49-4e10-8d99-c008af09b8ae}] Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 91.0.4472.114, chrome: {chromedriverVersion: 91.0.4472.101 (af52a90bf870..., userDataDir: /var/folders/p9/0lhk_6lj7x7...}, goog:chromeOptions: {debuggerAddress: localhost:9222}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, proxy: Proxy(), se:cdp: ws://localhost:9222/devtool..., se:cdpVersion: 91.0.4472.114, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true} Element: [[ChromeDriver: chrome on MAC (d05ff1a9794fef32216ef34021b22337)] -> id: username] Session ID: d05ff1a9794fef32216ef34021b22337

Upvotes: 1

Views: 2181

Answers (3)

YaDav MaNish
YaDav MaNish

Reputation: 1352

org.openqa.selenium.ElementClickInterceptedException
It display this exception when other element obscures the desired element

try to click on the element with the WebDriverWait locator stretegy

new WebDriverWait(driver,10)
    .pollingEvery(Duration.ofMillis(10))
    .ignoring(ElementClickInterceptedException.class)
    .until(ExpectedConditions
    .elementToBeClickable(By.id("web_element")))
    .click();

As you are executing the script in the headless mode, so
options.addArguments("--headless","--disable-notifications","--window-size=1920,1080")

* this is mentioned in the other answers as well

Upvotes: 0

cruisepandey
cruisepandey

Reputation: 29382

You need to take care of few things :

  1. Set the browser resolution to maximum :

    driver.maximize_window()
    

or if using chrome options :

options.add_argument("--window-size=1920,1080")
  1. Make use of ActionChains :

    ActionChains(driver).move_to_element(your web element here).click.perform()
    

This will be the imports :

from selenium.webdriver.common.action_chains import ActionChains

In place of your web element here you would need to pass driver.find_element(By.XPATH, "some xpath")

Upvotes: 0

Prophet
Prophet

Reputation: 33371

You did not present your code here, but I guess you are missing maximizing screen in headless mode.
So I think something like this should solve your problem:

opts.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors");

Upvotes: 0

Related Questions