简体   繁体   English

我想从登录后更改的页面获取文本 selenium java

[英]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我想从登录后打开的页面中获取文本,但我不知道该怎么做,目前 URL 是https://www.tdscpc.gov.in/app/login.xhtml登录后,它会打开一个页面https://www.tdscpc.gov.in/app/所以我想从第二页获取一个文本,谢谢

 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? Edit2-我认为驱动程序正在从第一个 URL 获取元素,这是无效的,因为该元素不存在在那里,我该如何更改它以便它从新页面而不是第一页检测到它?

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它一直等到您要到达的元素出现

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用带有Java的Selenium Webdriver从登录页面上的图像徽标获取文本 - how to get text from image logo on Login page using Selenium Webdriver with java 如何在 java selenium 中更改文本 - how to get changed text in java selenium 我想通过从Java应用程序传递凭据来登录到网页 - I want to login to a web page by passing credentials from java application Selenium(Java)从页面上显示的缩短中获取完整文本 - Selenium (Java) Get FULL text from shortened displayed on page 我想要一个方法,它可以等待页面中的所有webelements加载到java(Selenium webdiver) - i want a method which can will wait for all the webelements in a page to load in java(Selenium webdiver) Selenium 和 Java:如何在 WebElement 之后获取所有文本 - Selenium and Java: How do I get all of the text after a WebElement 我有一个登录和索引页面。 我想从索引重定向到登录但是找不到404 - I have one Login and index page. I want to redirect from index to login but get 404 not found 我想使用Java进行图书馆系统的简单登录。如何获取框架中的文本字段? - I want to make a simple login for a library system in Java.How can I get the text field in the frame? 如何使用Selenium Webdriver和Java从元素中获取文本? - How can I get text from element with Selenium webdriver and Java? 如何<a>使用Selenium</a>从<a>Java中</a>获取文本<a>?</a> - How can I get the text from <a> in java using selenium?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM