[英]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.