简体   繁体   中英

How to manage dynamic id for COMPOSE button in Gmail in Selenium Automated Test

The id of COMPOSE button of Gmail is dynamic. So when it is clicked different xpath is recorded by Selenium IDE as follows:

//div[@id=':lw']/div/div , //div[@id=':as']/div/div

What can be the alternative ways of using the id or xpath?

The following is the HTML for COMPOSE button:

<div class="aic" id=":as"><div class="z0"><div tabindex="0" role="button" class="T-I J-J5Ji L3 T-I-KE" style="-moz-user-select: none;" gh="cm">COMPOSE</div></div></div>

在Gmail中将以下代码用于COMPOSE

ClickAt   |  //div[text()='COMPOSE']

You should use CSS classes. They do not change in Gmail and this solution won't be locale dependent.

For the compose button the class is "TI J-J5-Ji L3".

An example using jQuery:

$('.T-I.J-J5-Ji.L3').live('click', function () {

     alert('Compose button clicked');

});

It is better to use Sikuli here.

Sikuli Script automates anything you see on the screen. It uses image recognition to identify and control GUI components. It is useful when there is no easy access to a GUI's internal or source code.

The following WebDriver Java code should work nicely:

driver.findElement(By.xpath("//div[text()='COMPOSE']")).click();

Using Selenium RC with Java:

selenium.click("//div[text()='COMPOSE']");

google uses dynamic ids for most of the elements. Try using the "Compose" text instead of using the ID.

you can use something like this. Webelement element = driver.findElementByXpath("//div[text()='COMPOSE']"); element.click();

hope this works!

I have sent an Emil successfully through selenium automation using Gmail Account Below is the script please find it:

WebDriver driver = new FirefoxDriver();

String baseUrl = "http://www.google.co.in/";
selenium = new WebDriverBackedSelenium(driver, baseUrl);

driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.findElement(By.xpath("//div[@id=':jb']/div[@class='z0']/div")).click(); // Compose

selenium.type("//div[@class='wO nr l1']//textarea[@name='to']", "vikramn@gmail.com"); // For To 
selenium.type("//div[@class='aoD az6']//input[@name='subjectbox']", "Wanted to SAY HI"); // For Subject
selenium.type("//div[@class='Ar Au']/div[@class='Am Al editable LW-avf']", "Hi Vikram");// For Message body
selenium.click("//div[@class='J-J5-Ji']/div[@class='T-I J-J5-Ji aoO T-I-atl L3']"); //send

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM