0

In the PeopleSoft page if I click on the lookup it pops up a new widget, I need to select one of the options.

The DOM has been designed in a way which has "style="overflow: hidden;"" in the body tag, with the below xpath I am able to identify the frame in google chrome, however, I couldn't switch to the frame and click on the option I need to select

HTML of the 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>

I tried with the below xpath to switch to the frame:

Xpath to switch to frame: //div[@id='pt_modals']/div[2]/div/div[2]/iframe[contains(@src,'https://*******')]

Xpath to select the option after switching:

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

Note: I also tried javascript executor.

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

I have just frame the same DOM,

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

I expect that it should click but it is not switching to the frame in first place.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Jagadeesh
  • 143
  • 2
  • 3
  • 14

2 Answers2

0

Try to wait frame using 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();
Sers
  • 12,047
  • 2
  • 12
  • 31
  • Thank you for the response, it also works after switching to the default content, driver.switchTo().defaultContent(); – Jagadeesh Mar 27 '19 at 12:56
0

To switch to the desired <iframe> so you have to induce WebDriverWait for the desired frame to be available and switch to it and you can use either of the Locator Strategies:

  • 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']")));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352