Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This is what the error displays when I use the xpath

XpathWhat command on the selenium webdriver would I use to click a text which has a xpath of

html/body/div[1]/div/div/div[2]/div[2]/div[2]/a

I tried using

driver.findElement(By.xpath("html/body/div[1]/div/div/div[2]/div[2]/div[2]/a")).click();

but still doesn't work... any suggestions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
298 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your xpath is incorrect. You are trying to hit an absolute path with html/body/div[1]/div/div/div[2]/div[2]/div[2]/a. You are missing a / so instead it should be /html/body/div[1]/div/div/div[2]/div[2]/div[2]/a

try:

driver.findElement(By.xpath("/html/body/div[1]/div/div/div[2]/div[2]/div[2]/a")).click();


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...