当前的gmail用户界面已更改,它会在弹出的DIV中打开,并且每个新的撰写窗口的ID参数都会发生变化。任何人都可以尝试给我代码吗?
答案 0 :(得分:4)
您可以使用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']"
答案 1 :(得分:0)
我找到了以下解决方案:
< TR>
<td>setTimeout</td>
<td>3000</td>
<td></td>
&LT; / tr&gt;
&LT; ! - 打开命令通常等待30秒,所以我们现在要求它只等待3秒 - &gt;
&LT; TR&GT;
<td>open</td>
<td>/mail/u/0/?shva=1#inbox?compose=new</td>
<td></td>
&LT; / TR&GT;
&LT; TR&GT;
<td>type</td>
<td>//table/tbody/tr[1]/td[2]/div/div/textarea</td>
<td>McKiran@example.com</td>
&LT; / TR&GT;
&LT; TR&GT;
<td>type</td>
<td>name=subjectbox</td>
<td>Test</td>
&LT; / TR&GT;
&LT; TR&GT;
<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>
&LT; / TR&GT;
&LT; TR&GT;
<td>click</td>
<td>class=T-I J-J5-Ji aoO T-I-atl L3</td>
<td></td>
&LT; / TR&GT;
答案 2 :(得分:0)
使用selenium webdriver
去抛出以下链接
http://ngowda.blogspot.in/2014/01/uploading-file-in-e-commerce-site-using.html
答案 3 :(得分:0)
public static void main(String [] args)抛出InterruptedException { System.setProperty(&#34; webdriver.chrome.driver&#34;&#34; d:\硒\ SeleniumWork \ seleniumDrivers \ chromedriver.exe&#34); WebDriver driver = new ChromeDriver(); 。driver.manage()窗口()最大化(); driver.get(&#34; https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/#identifier&#34); 如果(driver.findElement(By.xpath(&#34; .// [@ ID =&#39;电子邮件&#39;]&#34;。))的IsEnabled()) { driver.findElement(By.xpath(&#34; .// [@ ID =&#39;电子邮件&#39;]&#34))的SendKeys。(&#34; youremailid&#34) ; driver.findElement(By.xpath(&#34; .//* [@ ID =&#39;下一个&#39;]&#34))。单击(); } 了Thread.sleep(5000); WebElement menu = driver.findElement(By.xpath(&#34; .// input [@type =&#39; password&#39;]&#34;)); 如果(menu.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(&#34; // div [@ aria-label =&#39; Message Body&#39;]&#34;))。sendKeys(&#34; HI this is简单的消息&#34;); driver.findElement(By.xpath(&#34; // DIV [文本()=&#39;发送&#39;]&#34))。单击();
}