【问题标题】:How to automate new gmail UI to send email by using Selenium IDE?如何使用 Selenium IDE 自动化新的 gmail UI 以发送电子邮件?
【发布时间】:2013-04-21 19:32:55
【问题描述】:

当前的 gmail UI 已更改,它在弹出的 DIV 中打开,并且每个新的撰写窗口的 ID 参数都在更改。谁能给我代码?

【问题讨论】:

    标签: selenium ide gmail


    【解决方案1】:

    您可以使用 XPath 完成所有操作(使用 By.xpath("xpath expression") 查找):

    • 打开gmail页面
    • 照常登录
    • 点击撰写按钮(其 XPath 表达式:"//div[text()='COMPOSE']"
    • (将弹出电子邮件对话框)
    • 在“收件人”文本区域中键入(发送键)地址:"//textarea[@name='to']"
    • 在“主题”输入中键入(发送键)主题:"//input[@name='subjectbox']"
    • 将电子邮件内容键入(发送密钥)到可编辑的 div:"//div[@class='gmail_default']"(或 "//div[@aria-label='Message Body']"),因为他们似乎最近更改了 HTML)
    • 点击发送:"//div[text()='Send']"

    【讨论】:

    • 感谢这个 acdcjunior,但内容框由 iframe 提供,并且类已更改为“class=class=editable LW-avf”。无论如何,这与我自己发现的相似。实际上,我在定位 TO 字段的元素时遇到了一些问题。但现在解决了。
    • @MCKiran 好的,太好了!但是您确实知道如何通过 XPath 获取元素,对吧?使用 webdriver 会让你的生活变得更轻松。
    • 很好的答案!,如何添加附件?
    【解决方案2】:

    我找到了以下解决方案:

    <td>setTimeout</td>
    <td>3000</td>
    <td></td>
    

    <td>open</td>
    <td>/mail/u/0/?shva=1#inbox?compose=new</td>
    <td></td>
    

    <td>type</td>
    <td>//table/tbody/tr[1]/td[2]/div/div/textarea</td>
    <td>McKiran@example.com</td>
    

    <td>type</td>
    <td>name=subjectbox</td>
    <td>Test</td>
    

    <td>type</td>
    <td>class=editable LW-avf</td>
    <td>Hi All<br/>Hope the test is successful. <br/><br/><i> Lovingly, </i></br><b>McKiran.</b></td>
    

    <td>click</td>
    <td>class=T-I J-J5-Ji aoO T-I-atl L3</td>
    <td></td>
    

    【讨论】:

      【解决方案3】:

      【讨论】:

        【解决方案4】:

        public static void main(String[] args) 抛出 InterruptedException { System.setProperty("webdriver.chrome.driver","D:\Selenium\SeleniumWork\seleniumDrivers\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.get("https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/#identifier"); if(driver.findElement(By.xpath(".//[@id='Email']")).isEnabled()) { driver.findElement(By.xpath(".//[@id='Email']")).sendKeys("youremailid"); driver.findElement(By.xpath(".//*[@id='next']")).click(); } 线程.sleep(5000); WebElement menu = driver.findElement(By.xpath(".//input[@type='password']")); 如果(菜单。isEnabled()) {

                System.out.println("Hello world");
                 menu.sendKeys("emailidpassword");
                driver.findElement(By.xpath(".//*[@id='signIn']")).click();
            }
             Thread.sleep(5000);
             driver.findElement(By.xpath(".//div[contains(text(),'COMPOSE')]")).click();
             Thread.sleep(5000);
             driver.findElement(By.xpath("//textarea[@name='to']")).sendKeys("@gmail.com");
         driver.findElement(By.xpath("//input[@name='subjectbox']")).sendKeys("Sample");
        

        driver.findElement(By.xpath("//div[@aria-label='Message Body']")).sendKeys("你好,这是简单的消息"); driver.findElement(By.xpath("//div[text()='Send']")).click();

        }

        【讨论】:

        • 请格式化您的代码并解释为什么您提供的代码有效。谢谢!
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-26
        • 2020-07-12
        • 2014-08-27
        • 2018-02-23
        • 2021-01-24
        相关资源
        最近更新 更多