1
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;

public class SeleniumBasics {
    
public static void main(String[] args) {  
        
        WebDriver driver= new ChromeDriver();  
        driver.get("https://formy-project.herokuapp.com/");
        driver.manage().window().maximize(); 
        driver.findElement(By.xpath("//body/div[1]/div[1]/li[1]")).click();
        
    }  

}

Im trying to click on the element "autocomplete" in this page https://formy-project.herokuapp.com/...not working ..any help pleae?

Absolute Xpath relative Xpath find by element

2 Answers 2

2

you can use text() function to find element instead of using absolute xpath. //a[text()='Autocomplete']

Sign up to request clarification or add additional context in comments.

7 Comments

didn't work, I got an error. driver.findElement(By.xpath("//a[text()='autocomplete']")).click();
you should capitalize the "A" => "Autocomplete" like this. Because text() function will get the text between 2 tags <a></a>
Yes, I tried it first, didn't work either.
What's the error? Does it show element cannot be located?
Unable to find CDP implementation matching 126 juin 27, 2024 11:14:10 A.M. org.openqa.selenium.chromium.ChromiumDriver lambda$new$5 Unable to find version of CDP to use for 126.0.6478.1 You may need to include a dependency on a specific version of the CDP using something similar to org.seleniumhq.selenium:selenium-devtools-v86:4.16. where the version ("v86") matches the version of the chromium-based browser you're using and the version number of the artifact is the same as Selenium's. Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: element not interactable
|
0
//body/div[1]/div[1]/li[1]

You are locating the <li> element. You should be locating the <a> element.

Also don't use absolute XPath. Use relative XPath as below.

//a[@class='btn btn-lg' and text()='Autocomplete']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.