String split | Selenium Forum
M
Posted on 14/01/2016
Please let me know


for string Inbox (2) , how to capture 2.

one method is by using getchar at index.

can i capture 2 using string split and if yes , please explain

M
Replied on 15/01/2016

hi use this code.

[code:3ktwtuzt]package com.soapuitutorial.propertie;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class gmail {

/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.gmail.com/");
driver.findElement(By.xpath("//*[@id='Email']")).sendKeys("xxxxxxxxxxxx@gmail.com"+Keys.RETURN);
Thread.sleep(2000);
driver.findElement(By.xpath("//*[@id='Passwd']")).sendKeys("xxxxxxxxxx");
driver.findElement(By.xpath("//*[@id='signIn']")).click();
Thread.sleep(20000L);
String inbox=driver.findElement(By.xpath("//*[contains(@title,'Inbox')]")).getText();
String unreadInboxMails=inbox.substring(inbox.indexOf("(")+1,inbox.indexOf(")"));
System.out.println("inbox "+inbox);
System.out.println(unreadInboxMails);

List<WebElement> mailsObj=driver.findElements(By.xpath("//*[@class='zA zE']"));

System.out.println("total no of unread mails are==="+mailsObj.size());
mailsObj.get(0).click();



}

}

[/code:3ktwtuzt]