1

The compose button pressing command doesn't work. In output it shows Unable to locate element. At Compose its show third party iframe so even tried iframe but not working to navigate button.

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class mail {
    public static void main(String[] args) throws InterruptedException  {

        System.setProperty("webdriver.gecko.driver", "D:\mozilla   driver\geckodriver.exe");
        WebDriver driver=new FirefoxDriver();
        driver.get("https://www.mail.com/int/");
        driver.findElement(By.xpath(".//*[@id='login-button']")).click();
        driver.findElement(By.xpath(".//*[@id='login-email']")).sendKeys("rahulrahulxyz@mail.com");
        driver.findElement(By.xpath(".//*[@id='login-password']")).sendKeys("bangbang");
        driver.findElement(By.xpath(".//*[@id='login-form']/button")).click();
        Thread.sleep(8000);
        driver.findElement(By.xpath(".//*[@id='navigation']/ul/li[3]/a")).click();    //here is error
    }
}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

0

In gmail, there is text on the button that can be used to select it via XPath. I would presume there is something similar on the website you are automating

Here is what it looks like to find the "Compose" button in gmail:

driver.findElement(By.xpath(.//*[text()='COMPOSE']));
Rescis
  • 547
  • 5
  • 19
0

To click on the element with text as Compose E-mail once you login you have to switch to the <iframe> containing the intended element and then you should locate the intended element. You can use the following code block :

System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("https://www.mail.com/int/");
driver.findElement(By.xpath(".//*[@id='login-button']")).click();
driver.findElement(By.xpath(".//*[@id='login-email']")).sendKeys("rahulrahulxyz@mail.com");
driver.findElement(By.xpath(".//*[@id='login-password']")).sendKeys("bangbang");
driver.findElement(By.xpath(".//*[@id='login-form']/button")).click();
Thread.sleep(8000);
driver.switchTo().frame("thirdPartyFrame_home");
driver.findElement(By.linkText("Compose E-mail")).click();

Resultant Page Snapshot :

Compose E-mail

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank You. Its Working Now. But now when I navigate to "To" button, it again show unable to locate element. Code is: driver.switchTo().frame("thirdPartyFrame_mail"); driver.findElement(By.xpath(".//*[@id='idbd']/div[2]/div[1]/div[1]/div[2]/div/div/ul/li/input")).sendKeys("abcde@mail.com"); – shovit magar Apr 04 '18 at 09:10
  • @shovitmagar Great News !!! Can you raise a new question with your new requirement please, SO volunteers will be happy to help you out. – undetected Selenium Apr 04 '18 at 09:35
  • @ DebanjanB here is the link of another posted question https://stackoverflow.com/questions/49648759/unable-to-send-keys-to-mail-id-optioni-e-email-using-selenium-webdriver – shovit magar Apr 04 '18 at 10:34