0

I am trying to create a test where I have to fill out some information inside an iframe. Getting access to the iframe work fine and I can fill out information inside the frame. The issue is that when I find out a element 'A' it has a postback attached to it which reloads the content inside the iframe, to find out another element 'B'. So i am not able to find that element.I am getting below error:

org.openqa.selenium.WebDriverException: unknown error: Element <iframe style="overflow-x:hidden;" id="t5" height="1350" frameborder="0" width="98%" src="https://edata.ndtv.com/coronavirus/table/india_table.html?shgraph=1&amp;days=7" cd_frame_id_="7da8f2aea5a580b3a6e90a9d5016fa0d">...</iframe> is not clickable at point (554, 7). Other element would receive the click: <div class="topnav2014" style="border-bottom: none;">...</div>
  (Session info: chrome=85.0.4183.83)

Here are my observations: When I first locate the iframe it looks like this:

<iframe style="overflow-x:hidden;" id="t5" height="1350" frameborder="0" width="98%" src="https://edata.ndtv.com/coronavirus/table/india_table.html?shgraph=1&amp;days=7">

After the postback has occurred it looks like this:

<iframe style="overflow-x:hidden;" id="t5" height="1350" frameborder="0" width="98%" src="https://edata.ndtv.com/coronavirus/table/india_table.html?shgraph=1&amp;days=7" cd_frame_id_="a5006acf28d8c288313681ab9ad7a4fa">

I can easily find element A:

But element B i am not able to find The code fails when I try to get hold of the iframe element.

How can I get hold of the iframe again, after the postback inside the frame?

I have tried this suggestion also but it is not working

//Ensure that you are back to the base frame  
driver.SwitchTo().DefaultContent();
//SwitchTo the intended frame
 driver.SwitchTo().Frame(driver.FindElement(By.XPath("//iframe[contains(@src,'<removed for clearity>')]")));
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • if you can mention the steps to reproduce this with target url. – Dilip Meghwal Sep 11 '20 at 07:35
  • `Element ... is not clickable at point (554, 7)` means that you are able to find element, but you are not able to click it because another element overlap it. It can be popup or you need to scroll to your element. Also you can try to click using js. – Aliaksandr Plekhau Sep 11 '20 at 07:37
  • I still don't see the postback you mentioned within the question. Am I missing something? – DebanjanB Sep 11 '20 at 09:08
  • @DilipMeghwal This is the url i am trying: https://www.ndtv.com/coronavirus/india-covid-19-tracker----In this i am trying to automate i need to take state wise active cases. So for state wise active cases there are two xpath: private By TotalTodayActiveCasesforStatesDown=By.xpath("//tr//td[3]//p//span[@class='data-down']"); private By TotalTodayActiveCasesforStatesUp=By.xpath("//tr//td[3]//p//span[@class='data-up']"); – Manali Malkani Sep 12 '20 at 08:06
  • @AliaksandrPlekhau: I tried with javascript also its not working – Manali Malkani Sep 12 '20 at 08:11
  • @DebanjanB: There are two elements:private By TotalTodayActiveCasesforStatesDown=By.xpath("//tr//td[3]//p//span[@class='data-down']"); private By TotalTodayActiveCasesforStatesUp=By.xpath("//tr//td[3]//p//span[@class='data-up']"); When i try to click on second element its comes out of frame. Also when i am reopening the browser it is working fine. Please see the code below: – Manali Malkani Sep 12 '20 at 08:12
  • List elementsd = ct.TotalTodayActiveCasesforStatesDown(); for (WebElement element : elementsd) { String text= element.getText(); System.out.println(text); String TotalTodayStateCasedown=text.split("\\r?\\n")[0]; System.out.println(TotalTodayStateCasedown); elementssd = ct.TotalTodayActiveCasesforStatesUp(); for (WebElement element : elementssd) {String text= element.getText();System.out.println(text); – Manali Malkani Sep 12 '20 at 08:14
  • @ManaliMalkani Could you share all your code to reproduce the problem? – Aliaksandr Plekhau Sep 12 '20 at 08:15

3 Answers3

0

Use a driver.executescript() for the first problem since another element is receiving the click.

element = driver.findElement(By.id(""));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", element);
Arundeep Chohan
  • 6,219
  • 4
  • 6
  • 22
0

This error message...

org.openqa.selenium.WebDriverException: unknown error: Element <iframe style="overflow-x:hidden;" id="t5" height="1350" frameborder="0" width="98%" src="https://edata.ndtv.com/coronavirus/table/india_table.html?shgraph=1&amp;days=7" cd_frame_id_="7da8f2aea5a580b3a6e90a9d5016fa0d">...</iframe> is not clickable at point (554, 7). Other element would receive the click: <div class="topnav2014" style="border-bottom: none;">...</div>
  (Session info: chrome=85.0.4183.83)

...implies that the WebDriverException was raised as you tried to invoke click() on the <iframe> element.

Factually, instead of clicking on the <iframe> element you would invoke click() on an element within the <iframe>. Moreover, as the the desired element is within a <iframe> so you have to:

  • Induce WebDriverWait for the desired frameToBeAvailableAndSwitchToIt.
  • Induce WebDriverWait for the desired elementToBeClickable.
  • You can use either of the following Locator Strategies:
    • Using xpath:

      new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe_xpath")));
      new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("element_xpath"))).click();
      

References

You can find a couple of relevant discussions in:

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
0

I am able to extract the data of the active cases rise and fall for every state. There is a single frame which contains both the locators shared by you. Check below working code.

    driver.get("https://www.ndtv.com/coronavirus");
    driver.manage().window().maximize();
    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.until(ExpectedConditions.elementToBeClickable(By.className("tab-wrapper")));
    driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@src,'https://edata.ndtv.com/coronavirus/table/india_table.html?shgraph=1')]")));
    
    //cases down
    List<WebElement> eleCasesUp = driver.findElements(By.xpath("//tr//td[3]//p//span[@class='data-up']"));
    List<String> casesUpList = new ArrayList<String>();
    for (WebElement element : eleCasesUp) { 
        casesUpList.add(element.getText()); 
    }
    
    //cases up
    List<WebElement> eleCasesDown = driver.findElements(By.xpath("//tr//td[3]//p//span[@class='data-down']"));
    List<String> casesDownList = new ArrayList<String>();
    for (WebElement element : eleCasesDown) { 
        casesDownList.add(element.getText()); 
    }
    
    System.out.println("Cases Up List -->" + casesUpList);
    System.out.println("Cases Down List -->" + casesDownList);
Dilip Meghwal
  • 585
  • 4
  • 14