简体   繁体   中英

Unable to click on compose button in Gmail using selenium webdriver

My code is:

public class LoginGmail{    
public static void main(String[] args) throws InterruptedException  {   
    System.setProperty("webdriver.chrome.driver","D:/selenium/chromedriver_win32/chromedriver.exe"); 

     WebDriver fd= new ChromeDriver();
     fd.get("https://www.google.com/intl/en_in/gmail/about/");
        Thread.sleep(5000);
        fd.manage().window().maximize();
        WebElement e1=fd.findElement(By.xpath("html/body/nav/div/a[2]"));
        e1.click();
        WebElement username = fd.findElement(By.xpath(".//*[@id='identifierId']"));
        username.sendKeys("sharmi.paul87@gmail.com");

        WebElement username_click = fd.findElement(By.xpath(".//*[@id='identifierNext']/content/span"));
        username_click.click();

        WebDriverWait wait = new WebDriverWait(fd,30);
        wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@aria-label=\"Enter your password\"]")));
       WebElement password= fd.findElement(By.xpath("//input[@aria-label=\"Enter your password\"]"));
               password.sendKeys("pramilapaul");
        WebElement password_click = fd.findElement(By.xpath(".//*[@id='passwordNext']/content"));
        password_click.click();
    /*    --------------------------*/
        //fd.findElement(By.xpath("//div[contains(text(),'COMPOSE')]")).click();

        //WebElement button=fd.findElement(By.xpath("//div[contains(@id,':ir')]"));
        //WebElement buttton=fd.findElement(By.xpath("//div[@gh='cm']"));*/
        //WebElement button=fd.findElement(By.cssSelector(".aic div[role='button']"));
 //  button.click();

HTML code:

COMPOSE

in the above" / -- /" any xpath is not working. Can anyone help in this? The xpaths are showing unable to locate element or compound classes are prohibited errors.

This xpath "//div[@id=':ii']/div/div" OR .//div[normalize-space()='COMPOSE'] click the compose button for me.

Try this

driver.findElement(By.xpath("//div[@id=':ii']/div/div"));

Or

driver.findElement(By.xpath(".//div[normalize-space()='COMPOSE']"));

I wrote the given below program in WATIR and checked it,it works, you can use the same locators in your program and you can execute it.

b.goto("www.gmail.com")
b.a(:text, "Sign In").click
b.element(:id, "identifierId").send_keys "sharmi.paul87@gmail.com"
b.element(:css, "#identifierNext > content.CwaK9 > span.RveJvd.snByac").click
b.element(:name, "password").send_keys "pramilapaul"
b.element(:css, "span.RveJvd.snByac").click
b.element(:xpath, "//div[@id=':ii']/div/div").click

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