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"

huangapple go评论77阅读模式
英文:

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"

问题

我可以点击网站上的筛选选项,我的问题是“筛选选项是通过XPath打开的,同时筛选选项将被关闭”。

代码试验:

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);
英文:

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);

答案1

得分: 0

  • 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']"))));

英文:

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']"))));
    

huangapple
  • 本文由 发表于 2020年8月5日 02:08:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/63252752.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定