0

I am using Java with Selenium Webdriver. I am currently writing a script to verify a contact has been added to a contact list from a form. The workflow is:

The menu of our application uses Angular js while the rest is a frame.

Once I click on the menu I need "contacts", I then switch to frame, to interact with the objects in the iframe, I click on the list I would like to open, and within the frame, the page loads the the list of contacts. The issue I am having, once the list is loaded, the webdriver no longer can find the elements within the list.

source code:

<table width="100%" cellspacing="0" cellpadding="0" height="100%">
    <!--

     HEADER 

    -->
    <tbody>
        <tr></tr>
        <!--

         CONTENT 

        -->
        <tr>
            <td valign="top" height="*">
                <div id="listDetails" style="width: 958px; overflow: auto; border: 1px solid rgb(221, 221, 221); height: 694px;">
                    <table width="100%" cellspacing="0" cellpadding="5" border="0">
                        <!--

                         BEGIN HEADER 

                        -->
                        <tbody>
                            <tr style="background: url(../image/msn/table_heading.png) bottom left repeat-x"></tr>
                            <!--

                             END HEADER 

                            -->
                            <!--

                             BEGIN DATA ROWS 

                            -->
                            <tr class="rowEven" onmouseout="style.backgroundColor=''" onmouseover="style.backgroundColor='#FFFFCC'" style="">

<td nowrap="" align="left" style=" border-bottom: #DDDDDD dotted 1px; color: #666666; cursor:pointer; padding-right: 10px" onclick="openContact ('l-sf-lead-1f26:0')"></td>

My Code:

    String tableHeader = "//*[@id='listDetails']/table/tbody/tr[2]/td[1]";

    WebElement emailField = driver.findElement(By.id("login"));
    WebElement pwField =driver.findElement(By.id("pw"));
    WebElement loginBtn = driver.findElement(By.id("loginbutton"));
    //assertTrue("checking site title", driver.getTitle().startsWith("Act-On :: Login"));

    //Logging in -> to new ui.
    emailField.sendKeys(aoEmailtomcat8);
    pwField.sendKeys(password);
    loginBtn.click();
    Thread.sleep(1000);
    driver.navigate().to(newUI_URL);
    Thread.sleep(4000);

    //Clicks on Contacts Menu
    driver.findElement(By.xpath(contactsMenu)).click();
    driver.findElement(By.xpath(marketignListMenu)).click();
    driver.switchTo().frame("content");
    Thread.sleep(4000);

    //Clicks on List
    driver.findElement(By.xpath(defaultList)).click();
    Thread.sleep(1000);
    driver.findElement(By.xpath(fistItemList)).click();
    Thread.sleep(3000);

    //Does not locate the element, FAILS!
    driver.findElement(By.xpath(tableHeader));
  • Instead of thread.sleep , please use explicit wait to until element detect. – Helping Hands Apr 9 '15 at 4:23
1

Please post your frame html code.

Make sure your driver is switching to frame successfully. Is Content your frame name? You can switch to frame using three different ways.

driver.switchTo().frame(<frame name>);
driver.switchTo().frame(<frame index>); // Zero- based index
driver.switchTo().frame(<frame element>); // use driver.findElement method to find the frame first and pass as a parameter

As @Helping Hands said never use Thread.Sleep, use WebDriverWait to wait until page or element loads.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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