我試圖通過比較'歡迎用戶'文本與用戶名來驗證登錄。 comapriosn不匹配。當我用elem.getText()
打印xpath文本時,它會顯示包含選定文本的其他文本。無法通過xpath驗證登錄
任何人都可以提供有關如何編寫正確的xpaths或編寫更好的代碼來驗證登錄的建議嗎?
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class verify_loign
{
public static void main(String []args)
{
WebDriver driver;
ProfilesIni profile = new ProfilesIni();
FirefoxProfile fire_profile = profile.getProfile("sele_prac");
driver=new FirefoxDriver(fire_profile);
driver.get("https://phptravels.org/clientarea.php");
driver.findElement(By.id("inputEmail")).sendKeys("[email protected]");
driver.findElement(By.id("inputPassword")).sendKeys("123456");
driver.findElement(By.id("login")).submit();
WebElement verify_login_ele = driver.findElement(By.xpath("//div[@class='header-lined' and contains(h1,'Welcome Back, rakesh')]"));
// String str = "Welcome Back, rakesh";
// if(verify_login_ele.equals(str))
// {
// System.out.println("Your logged in succesfully");
// }
// else
// {
// System.out.println("Something went wrong with valid credential");
// }
System.out.println(verify_login_ele.getText());
driver.findElement(By.id("Secondary_Navbar-Account")).click();
driver.findElement(By.id("Secondary_Navbar-Account-Logout")).click();
driver.close();
driver.quit();
}
}
不是每個人都有帳戶phptravels.org ...你能分享'提到歡迎HTML'消息? – Andersson