使用 Selenium Java 测试用例调用 CLICK 时获取“org.openqa.selenium.ElementClickInterceptedException”

2023-12-07

我正在 Katalon Selenium IDE 中使用以下 java 代码。

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.*;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

  public static void setUp() throws Exception {
 System.setProperty("webdriver.chrome.driver", "C:\\Users\\myuser\\Downloads\\chromedriver_win32\\chromedriver.exe");
 driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
  }


public static void testQScan() throws Exception {
    driver.get("https://qualysguard.myorg.com/fo/login.php?idm_key=saml2_78743hhh43");
    WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='userNameInput']")));
    System.out.println("Title of the page is 8 -> " + driver.getTitle());
    driver.findElement(By.linkText("Scans")).click();
    System.out.println("Title of the page is 9 -> " + driver.getTitle());
}

启动基本 URL 后,应该单击“扫描”选项卡。 这工作正常,当使用 Selenium/Katalon 浏览器插件 IDE 播放时,“扫描”选项卡会被点击。

但是,运行导出的 java 代码会出现以下错误:

Output:

Title of the page is 8 -> Dashboard
Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <a onclick="javascript: showProcessing('...');" href="/fo/tools/module_landing.php?module=prod_scans" class="module-link">Scans</a> is not clickable at point (180, 100). Other element would receive the click: <div id="page-loading-mask" style="visibility: visible;">...</div>
  (Session info: chrome=77.0.3865.75)
Build info: version: '3.141.0', revision: '2ecb7d9a', time: '2018-10-31T20:09:30'
System info: host: 'AB-MYHOST7', ip: '10.9.9.112', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 77.0.3865.75, chrome: {chromedriverVersion: 77.0.3865.40 (f484704e052e0..., userDataDir: C:\Users\myuser\AppData\Loc...}, goog:chromeOptions: {debuggerAddress: localhost:51849}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 71b1daf7a06f6215547e7c79485c295e
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at pack.QScan.testQualysScan(QScan.java:139)
at pack.QScan.main(QScan.java:212)

请提供有关如何克服该错误的建议。

在浏览器上的“扫描”选项卡上查看源代码具有以下条目:

<div class="clear"></div>
<div id="top_modules_bar">
  <div class="module-tabs-tab module-tabs-tab-selected">
    <a onclick="javascript: showProcessing('Dashboard');" href="/fo/compliance/index.php?skip=1" class="module-link">Dashboard</a>
  </div>
  <div class="module-tabs-tab">
    <a onclick="javascript: showProcessing('Policies');" href="/fo/tools/module_landing.php?module=prod_policies" class="module-link">Policies</a>
  </div>
  <div class="module-tabs-tab">
    <a onclick="javascript: showProcessing('Scans');" href="/fo/tools/module_landing.php?module=prod_scans" class="module-link">Scans</a>
  </div>
  <div class="module-tabs-tab">
    <a onclick="javascript: showProcessing('Reports');" href="/fo/tools/module_landing.php?module=prod_reports" class="module-link">Reports</a>
  </div>
  <div class="module-tabs-tab">
    <a onclick="javascript: showProcessing('Exceptions');" href="/fo/tools/module_landing.php?module=prod_exceptions" class="module-link">Exceptions</a>
  </div>
  <div class="module-tabs-tab">
    <a onclick="javascript: showProcessing('Assets');" href="/fo/tools/module_landing.php?module=prod_assets" class="module-link">Assets</a>
  </div>
  <div class="module-tabs-tab">
    <a onclick="javascript: showProcessing('Users');" href="/fo/tools/module_landing.php?module=prod_users" class="module-link">Users</a>
  </div>
  <div class="clear"></div>
</div>

使用 Actions 类或 javascript 执行器:

Actions act =  new Actions(driver);
act.moveToElement(driver.findElement(By.linkText("Scans"))).click().perform();

OR

try {
     driver.findElement(By.linkText("Scans")).click();
  } catch (Exception e) {
     JavascriptExecutor executor = (JavascriptExecutor) driver;
     executor.executeScript("arguments[0].click();", driver.findElement(By.linkText("Scans")));
  }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Selenium Java 测试用例调用 CLICK 时获取“org.openqa.selenium.ElementClickInterceptedException” 的相关文章

  • 在 HTML SELECT 标记中禁用键盘

    我想禁用 HTML SELECT 标记的键盘 以便用户只能使用鼠标来选择选项 我试过了event cancelBubble true on the onkeydown onkeyup and onkeypress没有运气的事件 有任何想法吗
  • 如何将参数从jenkins传递到selenium

    我正在使用詹金斯和硒 我需要将测试 url 从 jenkins 发送到 selenium 服务器 在常规选项卡下 詹金斯字符串参数 Name APP Default Value http localhost basecode 在构建后操作下
  • 将二进制数据的 byte[] 转换为 String

    我有二进制格式的数据 hex 80 3b c8 87 0a 89 我需要将其转换为字符串 以便通过 Jackcess 将二进制数据保存在 MS Access 数据库中 我知道 我不打算在 Java 中使用 String 来存储二进制数据 但
  • 在 JSP 中对表单操作使用相对路径

    如何在表单操作中使用相对路径
  • Java 将字节转换为二进制安全字符串

    我有一些以字节为单位的数据 我想将它们放入Redis中 但是Redis只接受二进制安全字符串 而我的数据有一些二进制非安全字节 那么如何将这些字节转换为二进制安全字符串以便将它们保存到 Redis 中呢 Base64 对我有用 但它使数据更
  • 大小相同的表格单元格填充包含表格的整个宽度

    有没有办法使用 HTML CSS 具有相对大小调整 使一行单元格拉伸其所在表格的整个宽度 单元格的宽度应该相等 并且外表的大小也是动态的 table width 100 目前如果我不指定固定大小 单元格只是自动调整大小以适应其内容 您甚至不
  • 可以混合使用 JVM 语言吗?即:Groovy 和 Clojure

    我知道你可以轻松地混合groovy java clojure java 无论什么JvmLang java 这是否也意味着我也可以让 clojure 和 groovy 代码进行交互 如果我使用 Grails 或 jRoR 我也可以在该环境中使
  • IE 9 的子元素不透明,我无法使用 captify 阻止它

    好的 我正在使用一段名为 Captify 的 javascript 它为您的图像添加了一个带有文本的小弹出窗口 适用于所有接受 IE9 的浏览器 IE9 会淡化弹出 div 中的所有内容 我已阅读其子元素问题 但无法修复它 由于在网上任何地
  • Java 泛型和数字类型

    我想创建一个通用方法来有效地执行此操作 class MyClass static
  • KineticJS - 将舞台缩放到视口

    我正在努力将默认分辨率设置为 1366x756 我会根据视口来放大和缩小它 类似于此处显示的示例 http blogs msdn com b davrous archive 2012 04 06 modernizing your html5
  • 在 JSON 对象中强制执行非空字段

    我们的 REST API 接收一些 JSON 对象输入 其中某些字段要求不为空 这些可以是字符串 整数 甚至可以是其他一些类实例作为参考 我们正在尝试找到一种方法来强制这些字段不为空 而不是在 API 中进行空检查的正确方法 当前的 if
  • Java 中意外的负数

    import java util public class Prac9FibonacciNumbers public static void main String args int x new int 100 x 0 1 x 1 1 fo
  • 在 Java 中打开现有文件并关闭它。

    是否可以在java中打开一个文件附加数据并关闭多次 例如 psuedocode class variable declaration FileWriter writer1 new FileWriter filename fn1 writer
  • Android - 保持用户登录状态

    我正在尝试使用 PHP 和 MySQLi for Android 进行登录 我不明白的是如何保持用户登录状态 我看到一个简单的教程 其中有人使用 SQLite 来保护信息 但我不知道这是否真的安全 如何保存用户信息以保持用户登录状态 谢谢
  • 为什么这个 CSS nowrap 不起作用?

    我试图阻止 bar top container div 包裹它的内容 无论页面有多宽 即两个选择应该始终出现在同一行 但是当页面宽度太小而无法容纳它们时 这不起作用一方面 我该如何解决这个问题 Styles bar top containe
  • 网页抓取 - 如何识别网页上的主要内容

    给定一个新闻文章网页 来自任何主要新闻来源 例如时报或彭博社 我想识别该页面上的主要文章内容 并丢弃其他杂项元素 例如广告 菜单 侧边栏 用户评论 在大多数主要新闻网站上都可以使用的通用方法是什么 有哪些好的数据挖掘工具或库 最好是基于Py
  • WebSocketStompClient 将无法连接到 SockJS 端点

    我正在尝试新的 从版本 4 2 开始 java STOMP 客户端支持 我的出发点是入门指南 使用 WebSocket 构建交互式 Web 应用程序 http spring io guides gs messaging stomp webs
  • 有时 Properties.load() 会跳过行

    在以下情况下 Properties load 会跳过 InputStream 的第二行 这是 Java 的错误还是正常行为 public class PropTest public static void main String args
  • 对 Java 协议缓冲区对象进行一些小更改

    我想在 Java 协议缓冲区对象树的深处进行一个小更改 我可以使用 getBuilder 方法来创建一个新对象 该新对象是旧对象的克隆并进行一些更改 当深入完成此操作时 代码会变得丑陋 Quux Builder quuxBuilder fo
  • 按字母顺序对对象的 ArrayList 进行排序

    我必须创建一个方法来排序数组列表根据电子邮件按字母顺序排列对象 然后打印排序后的数组 我在排序时遇到麻烦的部分 我已经研究过并尝试使用Collections sort vehiclearray 但这对我不起作用 我是因为我需要一个叫做比较器

随机推荐