Reputation: 428
I am doing selenium practice and want to delete around 30K unread mails from my Gmail Inbox.I am Stuck on selecting the unread checkbox . tried lot of Locators and xpath But My xpath is selecting checkbox of All mail .
Can anyone suggest how to select checkbox of Unread Mails
PFB Java Selenium Code
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Unread_Gmail {
public static void main(String[] args) throws InterruptedException {
WebDriver driver;
driver = new FirefoxDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1#identifier");
driver.findElement(By.id("Email")).sendKeys("*********@gmail.com");
driver.findElement(By.id("next")).click();
driver.findElement(By.id("Passwd")).sendKeys("******");
driver.findElement(By.id("signIn")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//div[@class='G-tF']/div[1]/div")).click();
driver.findElement(By.xpath(".//*[@id=':z2']/div")).click();
//driver.findElement(By.xpath("//div[@class='J-J5-Ji J-JN-M-I-Jm'][1]")).click();
//driver.findElement(By.xpath("//div[@class='J-J5-Ji J-JN-M-I-Jm']")).click();
//driver.findElement(By.id("z2")).click();
//driver.findElement(By.xpath("//div[@class='J-N-Jz']")).click();
//driver.findElement(By.id("z2")).click();
}
}
Upvotes: 1
Views: 1109
Reputation: 26
//JavaMail is an API which can be used to handle different operations in selenium.
public static void main(String [] args){
String to="";
final String user="";
final String password="xxxxx";
//1) get the session object
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", "mail.javatpoint.com");
properties.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(properties, new javax.mail.Authenticator() {
protected PasswordAuthenticationgetPasswordAuthentication(){
return new PasswordAuthentication(user,password);
}
});
// add code here to handle mails
}
Upvotes: 0
Reputation: 1
You can try giving the number of the element, like 1
and 2
and try clicking.
driver.findElements(By.xpath("//*[@role='checkbox']")).get(1).click();
Upvotes: 0
Reputation: 153
In my case, the locator for 'unread' dropdown option looks like this:
<div class="J-N" selector="unread" role="menuitem" id=":dz" style="user-select: none;">
<div class="J-N-Jz" style="user-select: none;">Unread</div>
</div>
Looks like you need to look for element with class "J-N" and/or id ":dz".
Upvotes: 1
Reputation: 717
Are you familiar with Gmail API? If you want to just practice locators and so on, locating the checkbox is the way to go, but in "real life" when you have to verify/test smtp servers, using API is the way to go. Every email (thread) has a label, calling messagesUnread will return unreaded messeges. You can also use a query, which both in API and UI:
in:inbox is:unread
Upvotes: 4