Search code examples
seleniumautomationautomated-testsrobotframeworkselenium2library

GMail - waiting for the page for fully loaded


I am trying to automate gmail page (for some kind of email verification), after input username and password, I want to wait the page to fully loaded before continuing to my next action.

This is what I tried:

Selenium2Library.Input Text    //input[contains(@id, "identifierId")]    ${local_email_username}
Selenium2Library.Click Element    //span[text()="Berikutnya"]
Sleep    2s
Selenium2Library.Wait Until Element Is Visible    //input[contains(@name, "password")]    timeout=30s
Selenium2Library.Input Password    //input[contains(@name, "password")]    ${local_email_password}
Selenium2Library.Click Element    //span[text()="Berikutnya"]
Sleep    2s
Selenium2Library.Wait Until Element Is Visible    //input[contains(@aria-label, "Search")]    timeout=30s
### should be logged in to gmail
Log    >>> logged in to gmail. sleeping..
Sleep    5s
### make sure the email page fully loaded
Log    >>> making sure the email page fully loaded.. waiting new conversation button appeared
Comment    Wait Until Keyword Succeeds    10x    2s    Selenium2Library.Page Should Contain    ${email_name}
Wait Until Keyword Succeeds    20x    3s    Selenium2Library.Page Should Contain Element    //button[contains(@title, 'New conversation')]
Log    >>> email page fully loaded. start searching activation email...  

What I want to achieve is waiting for the new conversation button, that indicates that page is fully loaded (//button[contains(@title, 'New conversation')])

The problem is the script never finds the button. I tried to inspect and search for that xpath, and the element found.

Is there any solution for that?



Update: i tried using Select Frame like this.. like @Gaurav said.. here's the code:|

Selenium2Library.Select Frame    ${iframe_locator}
Wait Until Keyword Succeeds    20x    3s    Selenium2Library.Page Should Contain Element    //button[contains(@title, 'New conversation')]
Selenium2Library.Unselect Frame

where ${iframe_locator} is //body/div[7]/div[3]/div[1]/div[2]/div[1]/div[1]/div[3]/div[1]/div[1]/div[2]/div[1]/iframe[2]

but still no luck


Solution

  • The button is in iFrame, so you need to switch to that iFrame(there might be more iframes, so you need to switch to that specific one) and the look for //button[contains(@title, 'New conversation')]

    Here is Corresponding Java Implementation

        @Test
        public void newConversation() throws IOException, InterruptedException{
             driver.get("https://www.google.com/intl/hi/gmail/about/");
             driver.findElement(By.linkText("प्रवेश करें")).click();
             driver.findElement(By.id("identifierId")).sendKeys("*********@gmail.com");
             driver.findElement(By.id("identifierNext")).click();
             Thread.sleep(30000);
             driver.switchTo().frame(5);
             WebElement element = driver.findElement(By.xpath("//div[contains(@aria-label,'Change profile picture')]"));
             Actions action = new Actions(driver);
             action.moveToElement(element).build().perform();
             driver.findElement(By.xpath("//button[contains(@title,'New conversation')]")).click();
        }