0

Hey I'm new to web automation , I just startes to write my scenarios and link them to related steps using java framework:

I tried different methods for this button :

enter image description here

driver.findElement(By.xpath/className) 

and I always got this exception in my code:

org.openqa.selenium.NoSuchElementException

exemple used: WebElement filter = driver.findElement(By.xpath("//*[@id ='sidebarCollapse']"));
    filter.click();

Can anyone help me (see the attached image ) ?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
faith
  • 39
  • 4

1 Answers1

0

To click() on the element you can use either of the following Locator Strategies:

  • cssSelector:

    driver.findElement(By.cssSelector("span#sidebarCollapse[title='Filtres de recherche']")).click();
    
  • xpath:

    driver.findElement(By.xpath("//span[@id='sidebarCollapse' and @title='Filtres de recherche']")).click();
    

Ideally to click() on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("span#sidebarCollapse[title='Filtres de recherche']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@id='sidebarCollapse' and @title='Filtres de recherche']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Hello DebanjanB, I still get the error : no such element: Unable to locate element: , i tried both locators css & xpath :( – faith Dec 27 '21 at 08:18