0
package Practice_KingAllProg;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;


public class Crmpro_Iframe_King2410 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        try {
            System.setProperty("webdriver.chrome.driver",
                    "C:\\Users\\Sahil\\selelniumPratice\\Webdriver_PracticeKing\\src\\test\\resources\\BroWser_PracticeKing\\chromedriver.exe");
            WebDriver driver = new ChromeDriver();
            driver.get("https://www.crmpro.com/index.html");
            Thread.sleep(5000);
            driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
            driver.manage().window().maximize();
            driver.findElement(By.name("username")).sendKeys("sa12");
            driver.findElement(By.name("password")).sendKeys("vi123");
            driver.findElement(By.xpath("//*[@id=\'loginForm\']/div/div/input")).click();
            driver.switchTo().frame("leftpanel");
            Thread.sleep(5000);
            driver.switchTo().defaultContent();
        String Actualtext = driver.findElement(By.xpath("//html//body//table[1]//tbody//tr[1]//td//table//tbody//tr//td[1]")).getText();
        //html/body/table[1]/tbody/tr[1]/td/table/tbody/tr/td[1]
        System.out.println(Actualtext);
        String Exceptedtext="sanjay spear";
        if(Actualtext.equalsIgnoreCase(Exceptedtext))
        {
            System.out.println("Pass");
        }else
        {
            System.out.println("Fail");
        }

            driver.quit();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}
3
  • 2
    please share more context on your question, such as the target DOM, trim down your code snippet to the relevant point, and what is the result of your current solution. stackoverflow.com/help/how-to-ask – João Farias Nov 21 '19 at 15:47
  • Also, consider using a relative xpath rather than absolute one like in your example ("//html//body//table[1]//tbody//tr[1]//td//table//tbody//tr//td[1]"). You might be able to get some e.g. ids of elements in the DOM. – pavelsaman Nov 21 '19 at 15:57
  • Also remove implicit wait and add explicit wait in your test – PDHide Nov 21 '19 at 19:28