简体   繁体   中英

How to write xpath in selenium for Login link?

<a href="/MIS/PreLog/UserLogin.aspx" target="_blank">Login</a

I was trying to write the xpath for the above Login Link but it was not working.

driver.findElement( By.xpath("//a[contains(@href,'/MIS/PreLog/UserLogin.aspx') and  @id='login']" ).click();    

Please give me the solution for this..

In your xpath,

driver.findElement( By.xpath("//a[contains(@href,'/MIS/PreLog/UserLogin.aspx') and  @id='login']" ).click(); 

I don't see any @id attribute.

Also, why go for xpath specifically? You can use driver.findElement(By.LinkText("Login"))

Edit 1 : Try this

driver.findElement( By.xpath("//*[contains(@href,'UserLogin') and text()='Login']" )).click();

您的代码中的定位符可以如下修改和编写,请检查是否可以正常工作,

driver.findElement( By.xpath("//*[contains(@href,'UserLogin') and text()='Login']" )).click();

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