【问题标题】:Problem with Headless when running selenium test using java使用 java 运行 selenium 测试时出现 Headless 问题
【发布时间】:2021-06-24 07:28:05
【问题描述】:

我在无头模式下运行测试时遇到问题。我在两个不同的地方(网上商店和门户网站)编写了我的测试用例。同样,我使用的是 Headless,我的测试在 web-shop 中 headless 为 true 时有效,但在门户测试用例中 headless 为 true 时它们不起作用。

org.openqa.selenium.ElementClickInterceptedException: 元素点击 拦截:元素在点 (480, 483) 处不可点击。其他元素 将收到点击:...(会话信息: 无头铬= 91.0.4472.114)构建信息:版本:'4.0.0-beta-3', 修订:'5d108f9a67' 系统信息:主机:'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' 驱动信息: org.openqa.selenium.chrome.ChromeDriver 命令: [d05ff1a9794fef32216ef34021b22337,点击元素 {id=de6be461-9b49-4e10-8d99-c008af09b8ae}] 能力 {acceptInsecureCerts: false, browserName: chrome, browserVersion: 91.0.4472.114,铬:{chromedriverVersion:91.0.4472.101(af52a90bf870...,userDataDir:/var/folders/p9/0lhk_6lj7x7...}, goog:chromeOptions: {debuggerAddress: localhost:9222}, javascriptEnabled:真,networkConnectionEnabled:假, pageLoadStrategy:正常,平台:MAC,平台名称:MAC,代理: 代理(), se:cdp: ws://localhost:9222/devtool..., se:cdpVersion: 91.0.4472.114,setWindowRect:true,strictFileInteractability:false,超时:{implicit:0,pageLoad:300000,脚本:30000}, unhandledPromptBehavior:解雇并通知, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true} 元素:[[ChromeDriver: chrome on MAC (d05ff1a9794fef32216ef34021b22337)] -> id: 用户名] 会话 ID: d05ff1a9794fef32216ef34021b22337

【问题讨论】:

    标签: java selenium intellij-idea automated-tests headless


    【解决方案1】:

    你没有在这里展示你的代码,但我猜你错过了在无头模式下最大化屏幕。
    所以我认为这样的事情应该可以解决你的问题:

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

    【讨论】:

    • 对不起,我不能在这里分享代码,因为有不同的类,但我尝试了所有这些方法,但它不起作用
    【解决方案2】:

    你需要注意一些事情:

    1. 将浏览器分辨率设置为最大:

      driver.maximize_window()
      

    或者如果使用 chrome 选项:

    options.add_argument("--window-size=1920,1080")
    
    1. 利用ActionChains

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

    这将是 imports

    from selenium.webdriver.common.action_chains import ActionChains
    

    代替your web element here,您需要传递driver.find_element(By.XPATH, "some xpath")

    【讨论】:

    • 我做了所有,但不幸的是它不起作用,我们可以和团队一起打电话吗?
    • 在此之前可以分享网址吗?如果是公开的
    • 我在这两个站点进行测试
    • 它们都没有加载到我的本地
    【解决方案3】:
    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
    

    【讨论】:

      猜你喜欢
      • 2020-08-28
      • 1970-01-01
      • 2020-03-22
      • 1970-01-01
      • 2021-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多