【发布时间】:2013-04-21 19:32:55
【问题描述】:
当前的 gmail UI 已更改,它在弹出的 DIV 中打开,并且每个新的撰写窗口的 ID 参数都在更改。谁能给我代码?
【问题讨论】:
当前的 gmail UI 已更改,它在弹出的 DIV 中打开,并且每个新的撰写窗口的 ID 参数都在更改。谁能给我代码?
【问题讨论】:
您可以使用 XPath 完成所有操作(使用 By.xpath("xpath expression") 查找):
"//div[text()='COMPOSE']")"//textarea[@name='to']"
"//input[@name='subjectbox']"
"//div[@class='gmail_default']"(或 "//div[@aria-label='Message Body']"),因为他们似乎最近更改了 HTML)"//div[text()='Send']"
【讨论】:
我找到了以下解决方案:
<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>
【讨论】:
使用 selenium webdrier
去扔下面的链接
http://ngowda.blogspot.in/2014/01/uploading-file-in-e-commerce-site-using.html
【讨论】:
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();
}
【讨论】: