web-dev-qa-db-ja.com

Seleniumを使用してCLICKを呼び出すと「org.openqa.Selenium.ElementClickInterceptedException」を取得Javaテストケース

以下を使用していますJava= Katalon Selenium IDEのコード。

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=コードを実行すると、次のエラーが発生します。

出力:

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>
3
Ashar

Scans Induce WebDriverWaitおよびelementToBeClickable()をクリックし、Xpathオプションを実行するには

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@id='module-tabs-tab']//a[text()='Scans']"))).click();

または、アクションクラスを使用してクリックします。

WebElement scanEle =new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@id='module-tabs-tab']//a[text()='Scans']")));
Actions action =new Actions(driver);
action.moveToElement(scanEle).click().build().perform();
0
KunduK