![](/img/trans.png)
[英]how to get text from image logo on Login page using Selenium Webdriver with java
[英]I want to get a text from a page which is changed after login selenium java
我想從登錄后打開的頁面中獲取文本,但我不知道該怎么做,目前 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-我認為驅動程序正在從第一個 URL 獲取元素,這是無效的,因為該元素不存在在那里,我該如何更改它以便它從新頁面而不是第一頁檢測到它?
也許你可以使用
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("...")));
它一直等到您要到達的元素出現
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.