我能夠成功編寫郵件,但添加了郵件主題..我無法找到任何元素Xpath
或id
或className
來鍵入郵件正文。如何在selenium webdriver中輸入Gmail正文文本
我用過: - 鍵入(發送鍵)電子郵件內容到可編輯div:「// div [@ class ='gmail_default']」(或者「// div [@ aria-label ='Message身體']「)了Gmail正文..
driver.findElement(By.xpath("//div[@aria-label='Message Body']")).sendKeys("This is the test email send to test the selenium script.");
它的工作once..after它停止工作。
請任何人都可以幫忙... ****************** ****************** ******************* ***
public class TestSelenium {
public static void main(String[] args) throws InterruptedException{
System.setProperty("WebDriver.gecko.driver", "C:\\Users\\Administrator\\geckodriver-v0.14.0-win64\\geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.gmail.com/");
driver.manage().window().maximize();
WebElement id =driver.findElement(By.xpath(".//*[@id='Email']"));
id.click();
id.sendKeys("Email");
WebElement next = driver.findElement(By.xpath(".//*[@id='next']"));
next.click();
WebElement psw = driver.findElement(By.id("Passwd"));
psw.clear();
psw.sendKeys("Password");
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
WebElement login = driver.findElement(By.xpath(".//*[@id='signIn']"));
login.click();
WebElement compose = driver.findElement(By.xpath(".//*[@id=':44']/div/div"));
compose.click();
WebElement to = driver.findElement(By.className("vO"));
to.sendKeys("Email_id of Receiver");
WebElement sub = driver.findElement(By.className("aoT"));
sub.sendKeys("Login Successful");
driver.findElement(By.xpath("//div[@aria-label='Message Body']")).sendKeys("This is the test email send to test the selenium script.");
WebElement send = driver.findElement(By.xpath(".//*[@id=':8m']"));
send.click();
}}
爲什麼不使用Tab將控件從主題移動到消息主體。 –
我試着用TAB也可以,但是Tab給控件發送按鈕.. –
你可以提供一步一步的代碼。 –