【问题标题】:GMail - waiting for the page for fully loadedGMail - 等待页面完全加载
【发布时间】:2019-02-10 05:04:03
【问题描述】:

我正在尝试自动化 gmail 页面(用于某种电子邮件验证),在输入用户名和密码后,我想等待页面完全加载,然后再继续我的下一个操作。

这是我尝试过的:

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...  

我想要实现的是等待新的对话按钮,这表明页面已完全加载(//button[contains(@title, 'New conversation')])

问题是脚本永远找不到按钮。我试图检查并搜索该 xpath,并找到了该元素。

有什么解决办法吗?



更新: 我尝试像这样使用 Select Frame .. 就像@Gaurav 说的那样.. 这是代码:|

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

其中 ${iframe_locator} 是 //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]

但仍然没有运气

【问题讨论】:

    标签: selenium automation automated-tests robotframework selenium2library


    【解决方案1】:

    按钮在 iFrame 中,所以你需要切换到那个 iFrame(可能有更多 iframe,所以你需要切换到那个特定的)并查找 //button[contains(@title, 'New conversation')]

    这里是对应的Java实现

        @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();
        }
    

    【讨论】:

    • 它没有文字'新对话'顺便说一句
    • @thekucays...哦!问题是这个按钮在 iframe 中,让我更新我的答案
    • @thekucays..请你试试,我要去吃午饭了
    • 抱歉回复晚了..我已经更新了我的问题..你能看一下吗? :D
    • 你能用你自己的谷歌在你的机器上试试吗?我认为如果您当然使用默认主题,gmail主页将是相同的:D
    猜你喜欢
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多