英文:
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']"))));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论