Several of my tests refer to importBrokerCheckBox. But not all tests have to find it, because he must be absent. That is, if the element is on the page, then we must click on it, and if it is not there, we must go further through the code.But below code doesn't work and throws exception - xpath not found
importBrokerCheckBox = $x(".//div[text()='Брокер']/../../../preceding-sibling::span//span[@aria-label=\"caret-down\"]"),
if (importBrokerCheckBox.isDisplayed());
{
importBrokerCheckBox.click();
}
if (importBrokerSettingsCheckbox.isDisplayed());
{
importBrokerSettingsCheckbox.click();
}
There are basically two options:
NoSuchElementException
occured) the catch block code is executed (can be empty ofc).List<WebElement> elements = driver.findElements(By.by);
if no element is found, NoSuchElementException
is NOT thrown and the list stays empty like new ArrayList<WebElement>()
.