原创

Seleniumでclick()ができない

温馨提示:
本文最后更新于 2024年04月12日,已超过 37 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我

IDE 上のコード

チェックボックスをクリックしようとしていますが、クリックできません。

try {
    WebElement primaryParticipant = driver.findElement(By.xpath("//*[@id=\"searchable-list-input-primaryParticipantSearchable\"]"));
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
    WebElement other = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//li[5]/mat-checkbox[@class=\"mat-checkbox chp-ds pt-75 mat-primary ng-untouched ng-pristine ng-valid\"]")));
    ((JavascriptExecutor) driver).executeScript("arguments[0].click();", other);
    ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", primaryParticipant); //Scroll into the Additional Participants Section
    captureImage();
    Thread.sleep(2000);
    WebElement participantText = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class=\"mat-form-field-infix ng-tns-c14-7\"]/textarea")));
    participantText.click();
    Thread.sleep(2000);
    participantText.sendKeys("Automation Test");
    Thread.sleep(2000);
    captureImage();
} catch (Exception e) {
    captureImage();
    throw new AssertionError("Could not select Other on the checkbox or write on it.", e);
}

現在、JavaScriptでclick()を実行しようとしています。

org.openqa.selenium.ElementClickInterceptedException: element click intercepted:

そこでJavaScriptを使って試してみます。 Javascriptでクリックしようとすると、要素はクリックされず、次の変数participantTextが表示されないというエラーが発生します。おらず、TextArea が表示されていないためです。

「その他」次にどうすればよいですか?

正文到此结束
热门推荐
本文目录