Here is the screenshot of the html code HTML code screenshot

Here is the code I have written.

public void createPart() {

    try {

        driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);
        Select dropCountry = new Select(driver.findElement(By.id("txtNewLocation")));
        driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);

        //driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
        //driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);     
        String parentWindowHandler = driver.getWindowHandle(); // Store your parent window
        driver.findElement(By.xpath("//li[@class='icon-button add']/span")).click();

        driver.findElement(By.xpath("//label[starts-with(text(),'Create Part...')]")).click();
        driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);       
        String subWindowHandler = null;     
        Set<String> handles = driver.getWindowHandles(); // get all window handles
        Iterator<String> iterator = handles.iterator();
        while (iterator.hasNext()){
            subWindowHandler = iterator.next();

        WebDriverWait wait = new WebDriverWait(driver, 10);

        WebElement element = driver.findElement(By.xpath("//select[@id='Type-Field']//following-sibling::div//div//input"));





        driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);   

        WebElement frame1 = driver.findElement(By.xpath("//div[@id='pageContentDiv']//iframe"));
        WebElement frame2 = driver.findElement(By.xpath("//frame[@name='detailsDisplay']"));

        driver.findElement(By.xpath("//div[@class='categoryMenu']//following-sibling::div[2]//div//ul//li//div//a[@title='Part Details']")).click();;

    } catch (InterruptedException e) {
        // TODO Auto-generated catch block


Whats happening here is, I am clicking on a link called 'Create Part' which results a popup. i am changing the window handle. After filling the fields of 'Create Part' page, I am clicking on done. Popup gets automatically closed and I am returining to parent window handle.Main page is refreshed and shows new page. Now I am trying to click on 'Part Details' link which is inside frame 'detailsDisplay' and this frame is inside another iframe 'content'. I am switching to iframe first and frame next and trying to locate 'PartDetails' link, I am unable to locate the element. Here is the stack trace.:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no 
such element: Unable to locate element: 
sibling::div[2]//div//ul//li//div//a[@title='Part Details']"}

These are methods I have already tried. 1). Used different xpaths to locate the 'part Details' link 2). Used wait conditions for the element and frames to get loaded. 3). I am able to locate frames and element by xpaths in chrome but in code its not working.

I tried this code someone suggested.

// we find all iframes
        //int size = driver.findElements(By.tagName("iframe")).size();
        // we loop through all iframes to search for Part Details link
        for(int i=0; i<size; i++) {
            int total = driver.findElements(By.cssSelector("a[title*='Part Details']")).size();

The output of this code is all zeros. I really dont understand why I am not able to locate the element in the code.

Note: I have posted the issue but I didn't get solution for my issue. I am struggling with this issue quite a long time. I badly need a solution for this. I want to reach my issue as many people as possible. So, I am posting this again updated. Dont mark this as duplicate. Please suggest me useful solutions.

  • I appreciate you didn't get a working solution from your previous question, but posting the same question again isn't how stack exchange works. – trashpanda Jun 1 '18 at 9:53
  • I feel bad for you, however remember that your "struggling, the bad need, wanting to reach people, not marking as duplicate" are all your needs and not a reason for other people to help. The biggest reason to help is that you present a simple common problem that others will experience. Currently there is so much detail that this question is more of a "fix my problem" for me even if it doesn't help anyone else. Folks are less motivated by that – Michael Durrant Jun 1 '18 at 10:26

Instead of using switch frame, try using a selector that also takes the frame into account. My problem with frames has always been that I am unaware that they exists and/or I don't have them in the selector and though my selector is valid it simply doesn't work without the frame selector.

So I have learned that when there is a frame with an id of "f1" then my selector should be ( I use css when possible btw)

frame#f1 element#some_id

Not the answer you're looking for? Browse other questions tagged or ask your own question.