body标签被style="overflow: hidden;"隐藏时如何切换到一个frame

How to switchTo a frame when the body tag is hidden by style="overflow: hidden;"

在 PeopleSoft 页面中,如果我单击查找,它会弹出一个新的小部件,我需要 select 其中一个选项。

DOM 的设计方式是 "style="overflow: hidden;"" 在正文标签中,使用下面的 xpath 我能够识别 [=39] 中的框架=] chrome,但是,我无法切换到框架并单击我需要的选项 select

HTML 的 iframe:

<iframe frameborder="0" id="ptModFrame_2" name="ptModFrame_2" src="https://*******:8560/psc/umcssi2/EMPLOYEE/SA/c/SSR_PROG_ENRL.SSR_APT_REQ_RUNCNT.GBL?ICType=Panel&amp;ICElementNum=0&amp;ICStateNum=7&amp;ICResubmit=1&amp;ICAJAX=1&amp;" style="width: 514px; height: 350px;"></iframe>

我尝试使用以下 xpath 切换到框架:

切换到框架的 Xpath://div[@id='pt_modals']/div[2]/div/div[2]/iframe[contains(@src,'https://*******')]

Xpath to select切换后的选项:

driver.findElement(By.xpath("//table/tbody/tr[4]/td[1]")).click();

注意:我也试过javascript执行器。

js.executeScript("arguments[0].click();",driver.findElement(By.xpath("//table/tbody/tr[4]/td[1]")));

我刚刚画了一样DOM,

<body class="PSPAGE" id="ptifrmtemplate" style="overflow: hidden;"><div id="ptpopupmask" style="display: none;">&nbsp;</div>

我预计它应该会点击,但它不会首先切换到框架。

尝试使用 WebDriverWait

等待帧
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("ptModFrame_2")));

wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//table/tbody/tr[4]/td[1]"))).click();

要切换到所需的 <iframe>,因此您必须诱导 WebDriverWait 以使所需的 框架可用并切换到它 并且您可以使用 :

  • xpath:

    new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[starts-with(@id, 'ptModFrame_') and contains(@src, 'psc/umcssi2/EMPLOYEE/SA/c/SSR_PROG_ENRL.SSR_APT_REQ_RUNCNT.GBL')]")));
    
  • cssSelector:

    new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe[id^='ptModFrame_'][src*='psc/umcssi2/EMPLOYEE/SA/c/SSR_PROG_ENRL.SSR_APT_REQ_RUNCNT.GBL']")));