1

I am able to click on filter option on website,my question is " filter option was opened by using xpath and at a time filter option will be closed"

Code trials:

WebElement element= driver.findElement(By.xpath("//button[contains(@class,'slds-button slds-button--icon-border-filled action-control__button action-control--square')]"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
Divya Goud
  • 27
  • 5
  • 1
    Hi Divya, welcome to StackOverflow! Your question is not clear and your code is not formatted, so is difficult to understand, please read https://stackoverflow.com/help/how-to-ask and reformulate it with a good title, more context and formatted code, that will help people help you better! – moretti.fabio Aug 04 '20 at 20:18

1 Answers1

0

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

  • cssSelector:

    ((JavascriptExecutor) driver).executeScript("arguments[0].click();", new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.slds-button.slds-button--icon-border-filled.action-control__button.action-control--square"))));
    
  • xpath:

    ((JavascriptExecutor) driver).executeScript("arguments[0].click();", new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='slds-button slds-button--icon-border-filled action-control__button action-control--square']"))));
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • @DivyaGoud Glad to be able to help you. [Vote up questions and answers](https://stackoverflow.com/help/privileges/vote-up) that you found helpful for the benifit of the future readers. See [Why is voting important](https://stackoverflow.com/help/why-vote). – DebanjanB Aug 07 '20 at 11:16