Selenium 无法点击 google pay iframe 中的 div 按钮

问题描述 投票:0回答:1

目前正在从事谷歌支付集成测试自动化工作,并遇到了元素位置问题。 Google 付款流程在单独的窗口中打开,我通过在会话中找到正确的句柄来管理该窗口

driver.switchTo().window(googlePayWindowHandle);

在我转移到需要单击“继续”按钮的页面之后,有一些技巧:

  • 它位于 iframe 中,我通过移动到正确的框架来管理
WebElement iframe = checkPresenceOfElementWithWait(driver, By.name("sM432dIframe"), WAIT_DURATION);
WebDriver frameDriver = driver.switchTo().frame(iframe);
  • 我需要点击的按钮是一个带有 role="buttone" 的 div。 根据其他文章,我尝试定位按钮元素并等待它可点击
WebDriverWait frameWait = new WebDriverWait(frameDriver, WAIT_DURATION);
WebElement element = frameWait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@role='button']")));

但总是失败并出错

TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: //div[@role='buttone']

我还尝试了另一种方法,例如使用 waitForElementPresence ,似乎 selenium 无法在 iframe 内找到该元素。为了确保该按钮位于框架内,我进入了 chrome 控制台并通过 xPath 进行搜索,它起作用了。

附注: 也尝试了 javascript 执行器,但仍然没有成功。

java selenium-webdriver testing selenium-chromedriver automated-tests
1个回答
0
投票
ele="//div[text()='Pay']";

js.executeScript("arguments[0].click();", ele);

我将元素作为javascript执行器点击传递,它有效,但不适用于普通点击方法

© www.soinside.com 2019 - 2024. All rights reserved.