简体   繁体   中英

I want to get a text from a page which is changed after login selenium java

I want to get a text from a page which will be opened after I login, but I don't have an idea how to do so, currently the URL is https://www.tdscpc.gov.in/app/login.xhtml after login, it opens a page https://www.tdscpc.gov.in/app/ so I want to get a Text from the second page, thanks

 static WebDriver driver = new ChromeDriver();
    public static void main(String[] args) throws InterruptedException {
        String exePath = "C:\\Users\\Dell\\Downloads\\chromedriver_win32 (1)\\chromedriver.exe";
        System.setProperty("webdriver.chrome.driver", exePath);
        driver = new ChromeDriver();

        driver.get("https://www.tdscpc.gov.in/app/login.xhtml");
        driver.findElement(By.xpath("/html/body/div[1]/form/div[2]/div[2]/div[2]/div[2]/div[3]/table/tbody/tr/td[1]/input"))
                .click();
        driver.findElement(By.xpath("/html/body/div[1]/form/div[2]/div[2]/div[2]/div[2]/div[4]/p[2]/input"))
                .sendKeys("*******");
        driver.findElement(By.xpath("/html/body/div[1]/form/div[2]/div[2]/div[2]/div[2]/div[6]/p[2]/input"))
                .sendKeys("*******");
        driver.findElement(By.xpath("/html/body/div[1]/form/div[2]/div[2]/div[2]/div[2]/div[8]/p[4]/input[3]")).
                sendKeys("*******");
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        while (driver.findElement(By.xpath("/html/body/div[1]/form/div[2]/div[2]/div[2]/div[2]/div[12]/p[2]/input")).o) {

//This is the value which is on the new page, i want to get this value from the page, the page opens automatically once login is done, i just want to get this element froom a page which opens after login (Like the Dashboard) 
            String name = driver.findElement(By.xpath("/html/body/div[1]/div[3]/text()")).getText();
            String nameInReplace = name.replace("Welcome ", "");
            System.out.println(nameInReplace);
        }
    }

Edit2- I Think that the Driver is getting the Element from the first URL, which is invalid as the element is not present there, how do i change it so it detects it from the new page and not the first page?

maybe u can use

WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("...")));

it waits until the element you want to reach appears

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