How to use ElementNotSelectableException class of org.openqa.selenium package

Best Selenium code snippet using org.openqa.selenium.ElementNotSelectableException

ElementNotSelectableException org.openqa.selenium.ElementNotSelectableException;

ElementNotSelectableException raised when client script trying to select is an element which is not selectable

Like, when selenium tries to select script element which is unselectable then it throws ElementNotSelectableException.

Example

The below code snippet is an example of selecting an element . when the request element id is not selectable then selenium throws ElementNotSelectableException

copy
1WebElement selectElement = driver.findElement(By.id("selectElementID")); 2Select selectObject = new Select(selectElement);

Solutions

  • Verify element selection property before performing action
  • Use other interface to select element e.g. selectByIndex,selectByValue and selectByVisibleText
copy
1// Select an <option> based upon the <select> element's internal index 2selectObject.selectByIndex(1); 3 4// Select an <option> based upon its value attribute 5selectObject.selectByValue("value1"); 6 7// Select an <option> based upon its text 8selectObject.selectByVisibleText("Bread");

Code Snippets

Here are code snippets that can help you understand more how developers are using

Source:SeleniumDriver.java Github

copy

Full Screen

...11import com.testng.SpreeTestAutomation.Enummerables.Enums.LogType;12import com.testng.SpreeTestAutomation.HelperObjects.TestBase;13import org.openqa.selenium.JavascriptExecutor;14import org.openqa.selenium.By;15import org.openqa.selenium.ElementNotSelectableException;16import org.openqa.selenium.ElementNotVisibleException;17import org.openqa.selenium.StaleElementReferenceException;18import org.openqa.selenium.WebDriver;19import org.openqa.selenium.WebElement;20import org.openqa.selenium.chrome.ChromeDriver;21import org.openqa.selenium.chrome.ChromeOptions;22import org.openqa.selenium.firefox.FirefoxDriver;23import org.openqa.selenium.htmlunit.HtmlUnitDriver;24import org.openqa.selenium.ie.InternetExplorerDriver;25import org.openqa.selenium.interactions.Actions;26import org.openqa.selenium.remote.DesiredCapabilities;27import org.openqa.selenium.remote.RemoteWebDriver;28import org.openqa.selenium.safari.SafariDriver;29import org.openqa.selenium.support.ui.Select;30import java.net.URL;31/**32 *33 * @author OM2205434 */35public class SeleniumDriver extends TestBase36{37 38 public static final String USERNAME = "spree3";39 public static final String AUTOMATE_KEY = "coFkpCcqaYrspUvJTdoM";40 public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub.browserstack.com/wd/hub";41 42 private WebDriver webDriver;43 private final File browserDriverFile;44 private final BrowserType browserType;45 private boolean browserStarted = false;46 47 public SeleniumDriver(String driverLocation) throws Exception48 {49 this.browserDriverFile = new File(driverLocation);50 this.browserType = BrowserType.Chrome;51 52 System.setProperty("webdriver.chrome.driver", this.browserDriverFile.getAbsolutePath());53 }54 55 public SeleniumDriver() throws Exception56 {57 DesiredCapabilities caps = new DesiredCapabilities();58 caps.setCapability("browser", "Chrome");59 caps.setCapability("browser_version", "55.0");60 caps.setCapability("os", "Windows");61 caps.setCapability("os_version", "7");62 caps.setCapability("browserstack.debug", "true");63 caps.isJavascriptEnabled();64 65 webDriver = new RemoteWebDriver(new URL(URL), caps);66 this.browserType = null;67 this.browserDriverFile = new File(" ");68 }69 public boolean startWebDriver()70 {71 if(this.webDriver == null)72 {73 switch (browserType) 74 {75 case IE: 76 {77 this.webDriver = new InternetExplorerDriver();78 this.browserStarted = true;79 break;80 }81 case FireFox : 82 {83 this.webDriver = new FirefoxDriver();84 this.browserStarted = true;85 break;86 }87 case Chrome:88 {89 HashMap<String, Object> prefs = new HashMap<String, Object>();90 prefs.put("profile.default_content_setting_values.notifications", 2);91 ChromeOptions chromeOptions = new ChromeOptions();92 93 chromeOptions.setExperimentalOption("prefs", prefs);94 chromeOptions.addArguments("--kiosk");95 96 this.webDriver = new ChromeDriver(chromeOptions);97 this.browserStarted = true;98 break;99 }100 case Safari:101 {102 this.webDriver = new SafariDriver();103 this.browserStarted = true;104 break; 105 }106 case Headless:107 {108 this.webDriver = new HtmlUnitDriver();109 this.browserStarted = true;110 break; 111 }112 }113 } 114 this.webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);115 this.webDriver.manage().timeouts().pageLoadTimeout(2000, TimeUnit.SECONDS);116 this.webDriver.manage().window().maximize();117 118 logger.printLog(LogType.INFO,"WebDriver successfully started");119 120 return this.browserStarted;121 }122 public void NavigateToPage(String url) throws TimeoutException123 {124 try125 {126 webDriver.navigate().to(url); 127 logger.printLog(LogType.INFO,"NavigateToPage (" + url + ")");128 129 }130 catch(NoSuchElementException e)131 {132 logger.printLog(LogType.ERROR,"NavigateToPage (" + url + ") " + e.getMessage());133 134 throw(e);135 }136 }137 138 public WebElement FindWebElement(LocatorType locatorType, String value) 139 throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException140 {141 try142 {143 By locator = LocatorValue(locatorType, value);144 WebElement element = webDriver.findElement(locator);145 return element;146 }147 catch(NoSuchElementException e)148 {149 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());150 throw(e);151 }152 catch(StaleElementReferenceException e)153 {154 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());155 throw(e);156 }157 catch(ElementNotVisibleException e)158 {159 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());160 throw(e);161 }162 }163 public boolean CheckIfElementExist(LocatorType locatorType, String value) 164 throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException165 {166 try167 {168 Pause(2000);169 By locator = LocatorValue(locatorType, value);170 List<WebElement> element = webDriver.findElements(locator);171 172 if(!element.isEmpty())173 return true;174 else 175 return false;176 }177 catch(NoSuchElementException e)178 {179 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());180 throw(e);181 }182 catch(StaleElementReferenceException e)183 {184 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());185 throw(e);186 }187 catch(ElementNotVisibleException e)188 {189 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());190 throw(e);191 }192 193 }194 195 public boolean checkIfElementIsVisible(LocatorType locatorType, String value) 196 throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException197 {198 try199 {200 By locator = LocatorValue(locatorType, value);201 WebElement element = webDriver.findElement(locator);202 if(element.isDisplayed())203 return true;204 else 205 return false;206 207 }208 catch(NoSuchElementException e)209 {210 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());211 throw(e);212 }213 catch(StaleElementReferenceException e)214 {215 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());216 throw(e);217 }218 catch(ElementNotVisibleException e)219 {220 logger.printLog(LogType.ERROR,"Element not visible" + e.getMessage());221 throw(e);222 }223 224 }225 public boolean Enter_Text(LocatorType locatorType, String value, String text) 226 throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException227 {228 try 229 {230 By locator = LocatorValue(locatorType, value);231 WebElement element = webDriver.findElement(locator);232 element.clear();233 234 logger.printLog(LogType.INFO,"Enter_Text (" + text + ")");235 element.sendKeys(text);236 return true;237 }238 catch(NoSuchElementException e)239 {240 logger.printLog(LogType.ERROR,"Unable to find element: " + value + " \n" + e.getMessage());241 throw(e);242 }243 catch(StaleElementReferenceException e)244 {245 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + value + " \n" + e.getMessage());246 throw(e);247 }248 catch(ElementNotVisibleException e)249 {250 logger.printLog(LogType.ERROR,"Element not visible: " + value + " \n" + e.getMessage());251 throw(e);252 }253 }254 255 public boolean ClickElement(WebElement element) 256 throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException257 {258 try259 {260 logger.printLog(LogType.INFO,"ClickElement (" + element.getTagName() + ")");261 element.click();262 263 return true;264 }265 catch(NoSuchElementException e)266 {267 logger.printLog(LogType.ERROR,"Unable to find element: " + element.getTagName() + " \n" + e.getMessage());268 throw(e);269 }270 catch(StaleElementReferenceException e)271 {272 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + element.getTagName() + " \n" + e.getMessage());273 throw(e);274 }275 catch(ElementNotVisibleException e)276 {277 logger.printLog(LogType.ERROR,"Element not visible: " + element.getTagName() + " \n" + e.getMessage());278 throw(e);279 }280 }281 public boolean ClickElementByID(String id) 282 throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException283 {284 try285 {286 logger.printLog(LogType.INFO,"ClickElementByID (" + id + ")");287 webDriver.findElement(By.id(id)).click();288 289 return true;290 }291 catch(NoSuchElementException e)292 {293 logger.printLog(LogType.ERROR,"Unable to find element: " + id + " \n" + e.getMessage());294 throw(e);295 }296 catch(StaleElementReferenceException e)297 {298 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + id + " \n" + e.getMessage());299 throw(e);300 }301 catch(ElementNotVisibleException e)302 {303 logger.printLog(LogType.ERROR,"Element not visible: " + id + " \n" + e.getMessage());304 throw(e);305 }306 }307 308 public boolean ClickElementByName(String name) throws 309 NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException310 {311 try312 {313 logger.printLog(LogType.INFO,"ClickElementByName (" + name + ")");314 webDriver.findElement(By.name(name)).click();315 316 return true;317 }318 catch(NoSuchElementException e)319 {320 logger.printLog(LogType.ERROR,"Unable to find element: " + name + " \n" + e.getMessage());321 throw(e);322 }323 catch(StaleElementReferenceException e)324 {325 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + name + " \n" + e.getMessage());326 throw(e);327 }328 catch(ElementNotVisibleException e)329 {330 logger.printLog(LogType.ERROR,"Element not visible: " + name + " \n" + e.getMessage());331 throw(e);332 }333 } 334 335 public boolean ClickElementByClassName(String className) throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException336 {337 try338 {339 logger.printLog(LogType.INFO,"ClickElementByClassName (" + className + ")");340 webDriver.findElement(By.className(className)).click();341 342 return true;343 }344 catch(NoSuchElementException e)345 {346 logger.printLog(LogType.ERROR,"Unable to find element: " + className + " \n" + e.getMessage());347 throw(e);348 }349 catch(StaleElementReferenceException e)350 {351 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + className + " \n" + e.getMessage());352 throw(e);353 }354 catch(ElementNotVisibleException e)355 {356 logger.printLog(LogType.ERROR,"Element not visible: " + className + " \n" + e.getMessage());357 throw(e);358 }359 }360 361 public boolean ClickElementByCssSelector(String cssSelector) throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException362 {363 try364 {365 webDriver.findElement(By.cssSelector(cssSelector)).click();366 logger.printLog(LogType.INFO,"ClickElementByCssSelector (" + cssSelector + ")");367 return true;368 }369 catch(NoSuchElementException e)370 {371 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());372 throw(e);373 }374 catch(StaleElementReferenceException e)375 {376 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());377 throw(e);378 }379 catch(ElementNotVisibleException e)380 {381 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());382 throw(e);383 }384 }385 386 public boolean ClickElementByIDUsingJavaScript(String id) throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException387 {388 try389 {390 webDriver.findElement(By.id(id));391 392 WebElement element = this.webDriver.findElement (By.id(id));393 JavascriptExecutor executor = (JavascriptExecutor) this.webDriver;394 executor.executeScript ("arguments[0].click();" , element);395 396 logger.printLog(LogType.INFO,"ClickElementByIDUsingJavaScript(" + id + ")");397 return true;398 }399 catch(NoSuchElementException e)400 {401 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());402 throw(e);403 }404 catch(StaleElementReferenceException e)405 {406 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());407 throw(e);408 }409 catch(ElementNotVisibleException e)410 {411 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());412 throw(e);413 }414 }415 416 public boolean ClickElementByXpath(String Xpath) throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException417 {418 try419 {420 webDriver.findElement(By.xpath(Xpath)).click();421 logger.printLog(LogType.INFO,"ClickElementByXpath (" + Xpath + ")");422 return true;423 }424 catch(NoSuchElementException e)425 {426 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());427 throw(e);428 }429 catch(StaleElementReferenceException e)430 {431 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());432 throw(e);433 }434 catch(ElementNotVisibleException e)435 {436 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());437 throw(e);438 }439 }440 441 public boolean ClickElementByLinkText(String LinkText) throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException, ElementNotSelectableException442 {443 try444 {445 webDriver.findElement(By.linkText(LinkText)).click();446 logger.printLog(LogType.INFO,"ClickElementByLinkText (" + LinkText + ")");447 return true;448 }449 catch(NoSuchElementException e)450 {451 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());452 throw(e);453 }454 catch(StaleElementReferenceException e)455 {456 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());457 throw(e);458 }459 catch(ElementNotVisibleException e)460 {461 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());462 throw(e);463 } 464 catch(ElementNotSelectableException e)465 {466 logger.printLog(LogType.ERROR,"Element deems to be disabled: " + e.getMessage());467 throw(e);468 } 469 }470 public boolean ClickElementByPartialLinkText(String partialLinkText) throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException, ElementNotSelectableException471 {472 try473 {474 webDriver.findElement(By.partialLinkText(partialLinkText)).click();475 logger.printLog(LogType.INFO,"ClickElementByLinkText (" + partialLinkText + ")");476 return true;477 }478 catch(NoSuchElementException e)479 {480 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());481 throw(e);482 }483 catch(StaleElementReferenceException e)484 {485 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());486 throw(e);487 }488 catch(ElementNotVisibleException e)489 {490 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());491 throw(e);492 } 493 catch(ElementNotSelectableException e)494 {495 logger.printLog(LogType.ERROR,"Element deems to be disabled: " + e.getMessage());496 throw(e);497 } 498 }499 500 public boolean Select_From_Dropdown(com.testng.SpreeTestAutomation.Enummerables.Enums.LocatorType locatorType, String value, String text) 501 throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException, ElementNotSelectableException502 {503 try 504 {505 By locator;506 locator = LocatorValue(locatorType, value);507 WebElement element = webDriver.findElement(locator);508 Select dropDownList = new Select(element);509 dropDownList.selectByValue(text);510 logger.printLog(LogType.INFO,"Select_From_Dropdown (" + value + ")");511 return true;512 } 513 catch(NoSuchElementException e)514 {515 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());516 throw(e);517 }518 catch(StaleElementReferenceException e)519 {520 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());521 throw(e);522 }523 catch(ElementNotVisibleException e)524 {525 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());526 throw(e);527 } 528 catch(ElementNotSelectableException e)529 {530 logger.printLog(LogType.ERROR,"Element deems to be disabled: " + e.getMessage());531 throw(e);532 } 533 }534 535 public boolean HoverOverElementAndClickSubElement(List<LocatorType> locatorType, List<String> values) 536 throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException, ElementNotSelectableException537 { 538 try539 {540 By locator;541 locator = LocatorValue(locatorType.get(0), values.get(0)); 542 Pause(2000);543 Actions action = new Actions(webDriver); 544 WebElement menuHoverLink = webDriver.findElement(locator); 545 action.moveToElement(menuHoverLink).build().perform(); 546 logger.printLog(LogType.INFO,"HoverOverElementAndClickSubElement (" + values.get(0) + ")");547 548 Pause(2000);549 locator = LocatorValue(locatorType.get(1), values.get(1));550 action = new Actions(webDriver); 551 menuHoverLink = webDriver.findElement(locator);552 action.moveToElement(menuHoverLink).build().perform(); 553 action.moveToElement(menuHoverLink); 554 action.click(); 555 action.perform(); 556 logger.printLog(LogType.INFO,"HoverOverElementAndClickSubElement (" + values.get(1) + ")");557 558 return true; 559 560 }561 catch(NoSuchElementException e)562 {563 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());564 throw(e);565 }566 catch(StaleElementReferenceException e)567 {568 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());569 throw(e);570 }571 catch(ElementNotVisibleException e)572 {573 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());574 throw(e);575 }576 catch(ElementNotSelectableException e)577 {578 logger.printLog(LogType.ERROR,"Element deems to be disabled: " + e.getMessage());579 throw(e);580 } 581 582 }583 584 public boolean HoverOverElementAndClickSubElementCSS(List<LocatorType> locatorType, List<String> values) 585 throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException, ElementNotSelectableException 586 { 587 try588 {589 By locator;590 locator = LocatorValue(locatorType.get(0), values.get(0)); 591 Actions action = new Actions(webDriver); 592 WebElement menuHoverLink = webDriver.findElement(locator); 593 System.out.println(menuHoverLink.getText());594 action.moveToElement(menuHoverLink); 595 WebElement subMenuHoverLink = webDriver.findElement(locator);596 action.moveToElement(subMenuHoverLink).click().build().perform(); 597 return true; 598 599 }600 catch(NoSuchElementException e)601 {602 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());603 throw(e);604 }605 catch(StaleElementReferenceException e)606 {607 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());608 throw(e);609 }610 catch(ElementNotVisibleException e)611 {612 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());613 throw(e);614 }615 catch(ElementNotSelectableException e)616 {617 logger.printLog(LogType.ERROR,"Element deems to be disabled: " + e.getMessage());618 throw(e);619 } 620 621 }622 public String GetSubElementTextOnHover(List<LocatorType> locatorTypes, List<String> values)623 throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException, ElementNotSelectableException 624 {625 try626 {627 628 By locator = LocatorValue(locatorTypes.get(0), values.get(0)); 629 Actions action = new Actions(webDriver); 630 WebElement menuHoverLink = webDriver.findElement(locator); 631 action.moveToElement(menuHoverLink).build().perform(); 632 locator = LocatorValue(locatorTypes.get(1), values.get(1));633 WebElement subLink = menuHoverLink.findElement(locator); 634 635 636 return subLink.getText();637 }638 catch(NoSuchElementException e)639 {640 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());641 throw(e);642 }643 catch(StaleElementReferenceException e)644 {645 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());646 throw(e);647 }648 catch(ElementNotVisibleException e)649 {650 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());651 throw(e);652 }653 catch(ElementNotSelectableException e)654 {655 logger.printLog(LogType.ERROR,"Element deems to be disabled: " + e.getMessage());656 throw(e);657 } 658 }659 660 public boolean selectElementInUnOrderedList(LocatorType locatorType, String value)661 throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException, ElementNotSelectableException 662 {663 try664 {665 boolean found = false;666 667 By locator = LocatorValue(locatorType, value); 668 List<WebElement> allElements = webDriver.findElements(locator);669 WebElement element;670 671 for (int counter = 1; counter <= allElements.size(); counter++)672 {673 element = allElements.get(counter-1).findElement(By.xpath("//*[@id=\"size-select\"]/li["+counter+"]/input"));674 if(element.isEnabled())675 {676 element = allElements.get(counter-1).findElement(By.xpath("//*[@id=\"size-select\"]/li["+counter+"]/label"));677 678 System.out.println("Clicked: " + element.getText());679 680 found = true;681 element.click();682 683 break;684 }685 }686 687 return found;688 689 }690 catch(NoSuchElementException e)691 {692 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());693 throw(e);694 }695 catch(StaleElementReferenceException e)696 {697 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());698 throw(e);699 }700 catch(ElementNotVisibleException e)701 {702 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());703 throw(e);704 }705 catch(ElementNotSelectableException e)706 {707 logger.printLog(LogType.ERROR,"Element deems to be disabled: " + e.getMessage());708 throw(e);709 } 710 }711 712 public int getSizeOfAllElements(LocatorType locatorType, String value)713 throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException, ElementNotSelectableException 714 {715 try716 {717 By locator = LocatorValue(locatorType, value); 718 List<WebElement> allElements = webDriver.findElements(locator);719 720 return allElements.size();721 722 }723 catch(NoSuchElementException e)724 {725 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());726 throw(e);727 }728 catch(StaleElementReferenceException e)729 {730 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());731 throw(e);732 }733 catch(ElementNotVisibleException e)734 {735 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());736 throw(e);737 }738 catch(ElementNotSelectableException e)739 {740 logger.printLog(LogType.ERROR,"Element deems to be disabled: " + e.getMessage());741 throw(e);742 } 743 }744 745 public List<WebElement> getListAllElements(LocatorType locatorType, String value)746 throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException, ElementNotSelectableException 747 {748 try749 {750 By locator = LocatorValue(locatorType, value); 751 List<WebElement> allElements = webDriver.findElements(locator);752 753 return allElements;754 755 }756 catch(NoSuchElementException e)757 {758 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());759 throw(e);760 }761 catch(StaleElementReferenceException e)762 {763 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());764 throw(e);765 }766 catch(ElementNotVisibleException e)767 {768 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());769 throw(e);770 }771 catch(ElementNotSelectableException e)772 {773 logger.printLog(LogType.ERROR,"Element deems to be disabled: " + e.getMessage());774 throw(e);775 } 776 }777 778 public String GetElementText(LocatorType locatorType, String value)779 throws NoSuchElementException, StaleElementReferenceException, ElementNotVisibleException, ElementNotSelectableException 780 {781 try782 {783 By locator = LocatorValue(locatorType, value); 784 WebElement subLink = webDriver.findElement(locator); 785 786 return subLink.getText();787 }788 catch(NoSuchElementException e)789 {790 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());791 throw(e);792 }793 catch(StaleElementReferenceException e)794 {795 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());796 throw(e);797 }798 catch(ElementNotVisibleException e)799 {800 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());801 throw(e);802 }803 catch(ElementNotSelectableException e)804 {805 logger.printLog(LogType.ERROR,"Element deems to be disabled: " + e.getMessage());806 throw(e);807 } 808 }809 810 public By LocatorValue(LocatorType locatorType, String value) 811 {812 By by;813 switch (locatorType) 814 {815 case ID:816 by = By.id(value);817 break;818 case NAME:819 by = By.name(value);820 break;821 case XPATH:822 by = By.xpath(value);823 break;824 case CSS:825 by = By.cssSelector(value);826 break;827 case LINK_TEXT:828 by = By.linkText(value);829 break;830 case PARTIAL_LINK_TEXT:831 by = By.partialLinkText(value);832 break;833 case CLASS_NAME:834 by = By.className(value);835 break;836 default:837 by = null;838 break;839 }840 return by;841 }842 843 public int getUnOrderedListSize(LocatorType locatorType, String value)844 {845 try846 {847 int counter = 0;848 849 By locator = LocatorValue(locatorType, value); 850 List<WebElement> allElements = webDriver.findElements(locator);851 for (WebElement element: allElements) 852 { 853 counter++;854 }855 856 return counter;857 858 }859 catch(NoSuchElementException e)860 {861 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());862 throw(e);863 864 }865 catch(StaleElementReferenceException e)866 {867 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());868 throw(e);869 }870 catch(ElementNotVisibleException e)871 {872 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());873 throw(e);874 }875 catch(ElementNotSelectableException e)876 {877 logger.printLog(LogType.ERROR,"Element deems to be disabled: " + e.getMessage());878 throw(e);879 } 880 }881 882 public String getRandomItemInUnOrderedList(LocatorType locatorType, String value)883 {884 try885 {886 By locator = LocatorValue(locatorType, value); 887 List<WebElement> allElements = webDriver.findElements(locator);888 889 for (WebElement element: allElements) 890 {891 element = element.findElement(By.tagName("li"));892 return element.getText();893 894 }895 896 return "Not found";897 898 }899 catch(NoSuchElementException e)900 {901 logger.printLog(LogType.ERROR,"Unable to find element: " + e.getMessage());902 throw(e);903 }904 catch(StaleElementReferenceException e)905 {906 logger.printLog(LogType.ERROR,"Element not available in the DOM: " + e.getMessage());907 throw(e);908 }909 catch(ElementNotVisibleException e)910 {911 logger.printLog(LogType.ERROR,"Element not visible: " + e.getMessage());912 throw(e);913 }914 catch(ElementNotSelectableException e)915 {916 logger.printLog(LogType.ERROR,"Element deems to be disabled: " + e.getMessage());917 throw(e);918 } 919 }920 921 public boolean WaitForElement(org.openqa.selenium.WebElement element) throws TimeoutException, InterruptedException922 {923 boolean elementFound = false;924 int maxWaitTime = 60;925 int waitCount = 0;926 while(!elementFound && waitCount < maxWaitTime)927 {928 //if(webDriver.findElement(element))...

Full Screen

Full Screen

Source:Acciones.java Github

copy

Full Screen

...6 */7import org.openqa.selenium.By;8import org.openqa.selenium.ElementClickInterceptedException;9import org.openqa.selenium.ElementNotInteractableException;10import org.openqa.selenium.ElementNotSelectableException;11import org.openqa.selenium.NoSuchElementException;12import org.openqa.selenium.WebDriver;13import org.openqa.selenium.WebDriverException;14import org.openqa.selenium.WebElement;15import org.openqa.selenium.chrome.ChromeDriver;16import org.openqa.selenium.chrome.ChromeOptions;17/**18 *19 * @author archlinux20 */21public class Acciones {22 ChromeDriver driver;23 ChromeOptions chromeOptions = new ChromeOptions();24 public Acciones() {25 System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");26 chromeOptions.addArguments("--headless", "--disable-gpu", "--blink-settings=imagesEnabled=true");27 driver = new ChromeDriver();28 WebDriver driver = new ChromeDriver(chromeOptions);29 }30 public boolean abrirConexion() throws InterruptedException {31 boolean isOk = false;32 driver.get("https://computo.oep.org.bo/");33 Thread.sleep(500);34 return isOk;35 }36 public void buscarAca(int codMesa) throws InterruptedException {37 String xpathBotonActa= "//span[contains(text(),'ACTAS')]";38 do { 39 } while (!existeElemento(xpathBotonActa) || !sePuedeHacerClickElemento(xpathBotonActa));40// WebElement botonActa = driver.findElement(By.xpath(xpathBotonActa));41// botonActa.click();42 43 String xpathRadioButton= "//body[1]/app-root[1]/div[1]/div[1]/div[2]/div[1]/app-principal[1]/div[3]/div[1]/p-tabview[1]/div[1]/div[1]/p-tabpanel[2]/div[1]/app-acta[1]/div[1]/div[1]/form[1]/mat-radio-group[1]/div[1]/div[3]/mat-radio-button[1]/label[1]/div[2]";44 do { 45 } while (!existeElemento(xpathRadioButton) || !sePuedeHacerClickElemento(xpathRadioButton));46// WebElement radioButton = driver.findElement(By.xpath(xpathRadioButton));47// radioButton.click();48 49 String xpathCajaBuscarMesa="//input[@id='mat-input-0']";50 do { 51 } while (!existeElemento(xpathBotonActa));52 WebElement cajaBuscarMesa = driver.findElement(By.xpath(xpathCajaBuscarMesa));53 cajaBuscarMesa.clear();54 cajaBuscarMesa.sendKeys("" + codMesa);55 WebElement buttonBuscar = driver.findElement(By.xpath("//span[contains(text(),'BUSCAR')]"));56 buttonBuscar.click();57 58 String xpathbtnDesActa="//body/app-root[1]/div[1]/div[1]/div[2]/div[1]/app-principal[1]/div[3]/div[1]/p-tabview[1]/div[1]/div[1]/p-tabpanel[2]/div[1]/app-acta[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/p-tabview[1]/div[1]/div[1]/p-tabpanel[1]/div[1]/dx-toolbar[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/i[1]";59 do { 60 } while (!existeElemento(xpathbtnDesActa) || !sePuedeHacerClickElemento(xpathbtnDesActa));61// WebElement btnDesActa= driver.findElement(By.xpath(xpathbtnDesActa));62// btnDesActa.click();63 //64 if (existeProveido()) {65 WebElement btnProveido = driver.findElement(By.xpath("//span[contains(text(),'PROVEÍDO')]"));66 btnProveido.click();67 String xpathbtnDesProveido="//body/app-root[1]/div[1]/div[1]/div[2]/div[1]/app-principal[1]/div[3]/div[1]/p-tabview[1]/div[1]/div[1]/p-tabpanel[2]/div[1]/app-acta[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/p-tabview[1]/div[1]/div[1]/p-tabpanel[2]/div[1]/dx-toolbar[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/i[1]";68 do { 69 } while (!existeElemento(xpathbtnDesProveido) || !sePuedeHacerClickElemento(xpathbtnDesProveido));70// WebElement btnDesProveido= driver.findElement(By.xpath(xpathbtnDesProveido));71// btnDesProveido.click();72 System.out.println("Tiene proveido CodMesa:" + codMesa);73 } else {74 System.out.println("No tiene proveido CodMesa:" + codMesa);75 }76 }77 public void irAUnaURL(String url) {78 driver.get(url);79 }80 public void cerrarConexion() {81 driver.close();82 driver.quit();83 }84 public boolean existeProveido() throws InterruptedException {85 boolean present = false;86 try {87 driver.findElement(By.xpath("//span[contains(text(),'PROVEÍDO')]"));88 present = true;89 } catch (NoSuchElementException e) {90 present = false;91 }92 catch(ElementNotInteractableException e){93 present=false;94 Thread.sleep(100);95 System.out.println("++++++Exepcion: Elemento no interactuable"+e+",xpath");96 }97 catch (ElementNotSelectableException e){98 present= false;99 Thread.sleep(100);100 System.out.println("++++++Exepcion"+e+",xpath");101 }102 catch (WebDriverException e){103 present=false;104 Thread.sleep(5000);105 System.out.println("++++++Exepcion ERROR DE WEBDRIVER!!!!!!!!!!!!!!!!!!"+e+",xpath");106 }107 return present;108 }109 public boolean existeElemento(String xpath) throws InterruptedException{110 boolean sw=false;111 try{112 driver.findElement(By.xpath(xpath));113 sw=true;114 }catch(NoSuchElementException e){115 sw=false;116 Thread.sleep(100);117 System.out.println("-----Exepcion: No existe elemento:Esperando 5 seg"+e+",xpath");118 }119 catch(ElementNotInteractableException e){120 sw=false;121 Thread.sleep(100);122 System.out.println("++++++Exepcion: Elemento no interactuable"+e+",xpath");123 }124 catch (ElementNotSelectableException e){125 Thread.sleep(100);126 System.out.println("++++++Exepcion"+e+",xpath");127 }128 catch (WebDriverException e){129 sw=false;130 Thread.sleep(5000);131 System.out.println("++++++Exepcion ERROR DE WEBDRIVER!!!!!!!!!!!!!!!!!!"+e+",xpath");132 }133 return sw;134 }135 public boolean sePuedeHacerClickElemento(String xpath) throws InterruptedException{136 boolean sw = false;137 try{138 driver.findElement(By.xpath(xpath)).click();139 sw=true;140 }141 catch(ElementClickInterceptedException e){142 sw=false;143 Thread.sleep(100);144 System.out.println("++++++Exepcion: No se puede hacer click:Esperando 5 seg"+e+",xpath");145 }146 catch(ElementNotInteractableException e){147 sw=false;148 Thread.sleep(100);149 System.out.println("++++++Exepcion: Elemento no interactuable"+e+",xpath");150 }151 catch (ElementNotSelectableException e){152 sw=false;153 Thread.sleep(100);154 System.out.println("++++++Exepcion"+e+",xpath");155 }156 catch (WebDriverException e){157 sw=false;158 Thread.sleep(5000);159 System.out.println("++++++Exepcion ERROR DE WEBDRIVER!!!!!!!!!!!!!!!!!!"+e+",xpath");160 }161 return sw;162 }163}...

Full Screen

Full Screen

Source:TC001_NoSuchElementException.java Github

copy

Full Screen

...5import org.openqa.selenium.InvalidSelectorException;6import org.openqa.selenium.InvalidElementStateException;7import org.openqa.selenium.InvalidCookieDomainException;8import org.openqa.selenium.WebDriverException;9import org.openqa.selenium.ElementNotSelectableException;10import org.openqa.selenium.ElementNotVisibleException;11import org.openqa.selenium.ImeActivationFailedException;12import org.openqa.selenium.ImeNotAvailableException;13import org.openqa.selenium.InvalidArgumentException;14import org.openqa.selenium.NoAlertPresentException;15import org.openqa.selenium.NoSuchContextException;16import org.openqa.selenium.NoSuchCookieException;17import org.openqa.selenium.NoSuchElementException;18import org.openqa.selenium.NotFoundException;19import org.openqa.selenium.NoSuchFrameException;20import org.openqa.selenium.NoSuchSessionException;21import org.openqa.selenium.NoSuchWindowException;22import org.openqa.selenium.ScriptTimeoutException;23import org.openqa.selenium.SessionNotCreatedException;24import org.openqa.selenium.StaleElementReferenceException;25import org.openqa.selenium.TimeoutException;26import org.openqa.selenium.UnableToSetCookieException;27import org.openqa.selenium.UnexpectedAlertBehaviour;28import org.openqa.selenium.UnhandledAlertException;29import org.openqa.selenium.UnsupportedCommandException;30import java.util.concurrent.TimeUnit;31import org.openqa.selenium.Alert;32import org.openqa.selenium.By;33import org.openqa.selenium.JavascriptExecutor;34import org.openqa.selenium.WebDriver;35import org.openqa.selenium.WebElement;36import org.openqa.selenium.chrome.ChromeDriver;37import org.openqa.selenium.interactions.Actions;38import org.testng.annotations.Test;39import CommonUtil.TestBrowser;40public class TC001_NoSuchElementException {41 42 43 WebDriver driver;44 45 //https://www.seleniumhq.org/exceptions/stale_element_reference.jsp46 @Test47 public void Open_Mercury() throws Exception {48 49 //OpenChromeVrowser50 driver = TestBrowser.OpenChromeBrowser();51 52 //OpenUrl53 driver.get("https://www.encodedna.com/2013/07/dynamically-add-remove-form-elements-using-jquery-demo.htm");54 }55 56 public WebElement findElement(By by) throws Exception 57 {58 WebElement elem = driver.findElement(by); 59 60 if (driver instanceof JavascriptExecutor) 61 {62 ((JavascriptExecutor)driver).executeScript("arguments[0].style.border='3px solid red'", elem);63 64 }65 return elem;66 }67}68/*69 * 70 * NoSuchElementException71NoSuchWindowException72NoSuchFrameException73NoAlertPresentException74InvalidSelectorException75ElementNotVisibleException76ElementNotSelectableException77TimeoutException78NoSuchSessionException79StaleElementReferenceException80 */...

Full Screen

Full Screen

Source:SelectDropDown.java Github

copy

Full Screen

1package com.mba.commons.reusableFunction;2import java.util.List;3import org.openqa.selenium.By;4import org.openqa.selenium.ElementNotSelectableException;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.Select;8import org.openqa.selenium.support.ui.WebDriverWait;9import com.mba.commons.baseTest.BrowserFactory;10public class SelectDropDown extends BrowserFactory{11 12 Select select;13 String multivalue;14 public void singleValueSelect(String stringToBeSelect, String selectMethodName,int waitTime, By locator) {15 select=new Select(driver.findElement(locator));16 WebDriverWait wait = new WebDriverWait(driver, waitTime);17 wait.until(ExpectedConditions.visibilityOfElementLocated(locator));18 if(selectMethodName.equalsIgnoreCase("selectByVisibleText")) {19 try{20 select.selectByVisibleText(stringToBeSelect);21 }catch(ElementNotSelectableException e) {22 e.printStackTrace();23 }24 }else if(selectMethodName.equalsIgnoreCase("selectByValue")) {25 try{26 select.selectByValue(stringToBeSelect);27 }catch(ElementNotSelectableException e) {28 e.printStackTrace();29 }30 }else if(selectMethodName.equalsIgnoreCase("selectByIndex")) {31 try{32 int index = Integer.parseInt(stringToBeSelect); 33 select.selectByIndex(index);34 }catch(ElementNotSelectableException e) {35 e.printStackTrace();36 }37 }38 } 39 public void multiValueSelect(By locator,String[] stringToBeSelect, String selectMethodName) throws InterruptedException {40 Select select = new Select(driver.findElement(locator)); 41 List<WebElement> list=select.getOptions();42 for(int i=0;i<list.size();i++) {43 String value=list.get(i).getText();44 for(int j=0;j<stringToBeSelect.length;j++) {45 if(value.contains(stringToBeSelect[j])) {46 if(selectMethodName.equalsIgnoreCase("selectByVisibleText")) {47 try{48 select.selectByVisibleText(stringToBeSelect[j]);49 }catch(ElementNotSelectableException e) {50 e.printStackTrace();51 }52 }else if(selectMethodName.equalsIgnoreCase("selectByValue")) {53 try{54 select.selectByValue(stringToBeSelect[j]);55 }catch(ElementNotSelectableException e) {56 e.printStackTrace();57 }58 }else if(selectMethodName.equalsIgnoreCase("selectByIndex")) {59 try{60 int index = Integer.parseInt(stringToBeSelect[j]); 61 select.selectByIndex(index);62 }catch(ElementNotSelectableException e) {63 e.printStackTrace();64 }65 }66 }67 }68 }69 }70}...

Full Screen

Full Screen

Source:DropDowns.java Github

copy

Full Screen

1package practise;2import java.util.List;3import java.util.concurrent.TimeUnit;4import org.openqa.selenium.By;5import org.openqa.selenium.ElementNotSelectableException;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.firefox.FirefoxDriver;9import org.openqa.selenium.support.ui.Select;10public class DropDowns {11 public static void main(String[] args) throws InterruptedException {12 WebDriver driver; //Refer "https://saucelabs.com/resources/articles/selenium-tips-css-selectors"13 String baseurl = "https://letskodeit.teachable.com/p/practice";14 String userDir = System.getProperty("user.dir");15 16 System.setProperty("webdriver.gecko.driver", userDir+"\\src\\main\\java\\resources\\geckodriver.exe");17 driver = new FirefoxDriver();18 driver.manage().window().maximize();19 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);20 driver.get(baseurl);21 22 try {23 WebElement carSelection = driver.findElement(By.id("carselect"));24 Select ele = new Select(carSelection);25 26 ele.selectByIndex(0);27 System.out.println(ele.getAllSelectedOptions().get(0).getText());28 Thread.sleep(1000);29 30 ele.selectByValue("benz");31 System.out.println(ele.getAllSelectedOptions().get(0).getText());32 Thread.sleep(1000);33 34 ele.selectByVisibleText("Honda");35 System.out.println(ele.getAllSelectedOptions().get(0).getText());36 Thread.sleep(1000);37 } catch (ElementNotSelectableException e) {38 System.out.println("Fail | Element not selectable");39 }40 41 try{42 WebElement multiSelect = driver.findElement(By.name("multiple-select-example"));43 Select ele = new Select(multiSelect);44 45 ele.selectByIndex(0);46 List<WebElement> allSelOptions = ele.getAllSelectedOptions();47 for (WebElement ele1:allSelOptions) {48 System.out.println(ele1.getText());49 }50 Thread.sleep(1000);51 52 ele.selectByValue("orange");53 List<WebElement> allSelOptions1 = ele.getAllSelectedOptions();54 for (WebElement ele1:allSelOptions1) {55 System.out.println(ele1.getText());56 }57 Thread.sleep(1000);58 59 ele.selectByVisibleText("Peach");60 List<WebElement> allSelOptions2 = ele.getAllSelectedOptions();61 for (WebElement ele1:allSelOptions2) {62 System.out.println(ele1.getText());63 }64 Thread.sleep(1000);65 66 ele.deselectAll();67 System.out.println(multiSelect.isSelected());68 69 } catch (ElementNotSelectableException e) {70 System.out.println("Fail | Element not selectable");71 }72 73 driver.quit();74 }75}...

Full Screen

Full Screen

Source:FluentWaitHelpers.java Github

copy

Full Screen

2import java.time.Duration;3import java.util.NoSuchElementException;4import java.util.concurrent.TimeUnit;5import org.openqa.selenium.ElementNotInteractableException;6import org.openqa.selenium.ElementNotSelectableException;7import org.openqa.selenium.ElementNotVisibleException;8import org.openqa.selenium.StaleElementReferenceException;9import org.openqa.selenium.WebDriver;10import org.openqa.selenium.WebElement;11import org.openqa.selenium.support.ui.FluentWait;12import freemarker.template.utility.Constants;13public class FluentWaitHelpers {14 15 16 17// public WebElement fluentWait(WebDriver driver,String exceptiontobeignored) {18// 19// FluentWait<WebDriver> fluentWait;20// String exceptionType=exceptiontobeignored.toLowerCase();21// 22// switch(exceptionType) {23// 24// case "staleelementexception":25// fluentWait = new FluentWait<WebDriver>(driver)26// .withTimeout(30,TimeUnit.SECONDS)27// .pollingEvery(5,TimeUnit.SECONDS)28// .ignoring(StaleElementReferenceException.class);29// break;30// case "elementnotinteractableexception":31// fluentWait = new FluentWait<WebDriver>(driver)32// .withTimeout(Duration.ofSeconds(Constants.mxaximumFluentWait))33// .pollingEvery(Duration.ofSeconds(Constants.pollingWait))34// .ignoring(ElementNotInteractableException.class);35// break;36// case "elementnotselectableexception":37// fluentWait = new FluentWait<WebDriver>(driver)38// .withTimeout(Duration.ofSeconds(Constants.mxaximumFluentWait))39// .pollingEvery(Duration.ofSeconds(Constants.pollingWait))40// .ignoring(ElementNotSelectableException.class);41// break;42// case "elementnotvisibleexception":43// fluentWait = new FluentWait<WebDriver>(driver)44// .withTimeout(Duration.ofSeconds(Constants.mxaximumFluentWait))45// .pollingEvery(Duration.ofSeconds(Constants.pollingWait))46// .ignoring(ElementNotVisibleException.class);47// break;48// 49// default :50// fluentWait = new FluentWait<WebDriver>(driver)51// .withTimeout(Duration.ofSeconds(Constants.mxaximumFluentWait))52// .pollingEvery(Duration.ofSeconds(Constants.pollingWait))53// .ignoring(NoSuchElementException.class);54// break;...

Full Screen

Full Screen

Source:HomePage.java Github

copy

Full Screen

1package com.pages;2import static com.codeborne.selenide.Selenide.*;3import org.openqa.selenium.By;4import org.openqa.selenium.ElementNotInteractableException;5import org.openqa.selenium.ElementNotSelectableException;6import org.openqa.selenium.NoSuchElementException;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.support.FindBy;9import org.openqa.selenium.support.PageFactory;10import com.base.BaseClass;11public class HomePage extends BaseClass {12 // Defining the Object Repository for HomePage13 @FindBy(linkText = "Chapter1")14 WebElement linkChapter1;15 public HomePage() {16 // This initElements method will trigger/initiate all WebElements within this17 // page18 PageFactory.initElements(driver, this);19 }20 public void clickLinkChapter1() {21 try {22 $(By.linkText("Chapter1")).click();23 } catch (ElementNotInteractableException e) {24 e.printStackTrace();25 } catch (ElementNotSelectableException e) {26 e.printStackTrace();27 } catch (NoSuchElementException e) {28 e.printStackTrace();29 }30 }31}...

Full Screen

Full Screen

Source:Chapter1Page.java Github

copy

Full Screen

2import static com.codeborne.selenide.Selenide.*;3import static com.codeborne.selenide.Condition.*;4import org.openqa.selenium.By;5import org.openqa.selenium.ElementNotInteractableException;6import org.openqa.selenium.ElementNotSelectableException;7import org.openqa.selenium.NoSuchElementException;8import org.openqa.selenium.WebElement;9import org.openqa.selenium.support.FindBy;10import org.openqa.selenium.support.PageFactory;11import com.base.BaseClass;12public class Chapter1Page extends BaseClass {13 @FindBy(id = "divontheleft")14 WebElement textToAssert;15 @FindBy(linkText = "Home Page")16 WebElement linkHomePage;17 public Chapter1Page() {18 PageFactory.initElements(driver, this);19 }20 public void clickHomeLink() {21 try {22 $(By.linkText("Home Page")).click();23 } catch (ElementNotInteractableException e) {24 e.printStackTrace();25 } catch (ElementNotSelectableException e) {26 e.printStackTrace();27 } catch (NoSuchElementException e) {28 e.printStackTrace();29 }30 }31}

Full Screen

Full Screen

ElementNotSelectableException

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.support.ui.Select;6import org.openqa.selenium.ElementNotSelectableException;7public class ElementNotSelectableExceptionExample {8 public static void main(String[] args) {9 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Karthik\\Downloads\\chromedriver_win32\\chromedriver.exe");10 WebDriver driver = new ChromeDriver();11 WebElement element = driver.findElement(By.id("select-demo"));12 Select select = new Select(element);13 try {14 select.selectByIndex(4);15 } catch (ElementNotSelectableException e) {16 System.out.println("ElementNotSelectableException");17 }18 driver.quit();19 }20}

Full Screen

Full Screen

ElementNotSelectableException

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.ElementNotSelectableException;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.chrome.ChromeOptions;7import org.openqa.selenium.support.ui.Select;8public class ElementNotSelectableExceptionDemo {9public static void main(String[] args) {10ChromeOptions options = new ChromeOptions();11options.addArguments("--disable-extensions");12WebDriver driver = new ChromeDriver(options);13driver.manage().window().maximize();14WebElement element = driver.findElement(By.id("continents"));15Select select = new Select(element);16try {17select.selectByVisibleText("Africa");18} catch (ElementNotSelectableException e) {19System.out.println(e.getMessage());20}21driver.close();22}23}24package org.seleniumhq.selenium.selenium_java;25import org.openqa.selenium.By;26import org.openqa.selenium.ElementNotInteractableException;27import org.openqa.selenium.WebDriver;28import org.openqa.selenium.WebElement;29import org.openqa.selenium.chrome.ChromeDriver;30import org.openqa.selenium.chrome.ChromeOptions;31public class ElementNotInteractableExceptionDemo {32public static void main(String[] args) {33ChromeOptions options = new ChromeOptions();34options.addArguments("--disable-extensions");35WebDriver driver = new ChromeDriver(options);36driver.manage().window().maximize();

Full Screen

Full Screen

ElementNotSelectableException

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.ElementNotSelectableException;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeDriver;4import org.openqa.selenium.By;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.support.ui.Select;7import org.openqa.selenium.support.ui.ExpectedConditions;8import org.openqa.selenium.support.ui.WebDriverWait;9public class ElementNotSelectableExceptionExample {10 public static void main(String[] args) {11 WebDriver driver;12 System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");13 driver = new ChromeDriver();14 driver.manage().window().maximize();15 Select select = new Select(driver.findElement(By.id("select-demo")));16 try {17 select.selectByVisibleText("Monday");18 }19 catch(ElementNotSelectableException e) {20 System.out.println("Element is not selectable");21 }22 driver.quit();23 }24}

Full Screen

Full Screen

ElementNotSelectableException

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.ElementNotSelectableException;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.support.ui.Select;6public class ElementNotSelectableExceptionDemo {7 public static void main(String[] args) throws InterruptedException {8 System.setProperty("webdriver.chrome.driver", "D:\\SeleniumDrivers\\chromedriver.exe");9 WebDriver driver = new ChromeDriver();10 driver.manage().window().maximize();11 WebElement day = driver.findElement(By.id("day"));12 WebElement month = driver.findElement(By.id("month"));13 WebElement year = driver.findElement(By.id("year"));14 Select daySelect = new Select(day);15 Select monthSelect = new Select(month);16 Select yearSelect = new Select(year);17 try {18 daySelect.selectByValue("20");19 monthSelect.selectByValue("6");20 yearSelect.selectByValue("1990");21 } catch (ElementNotSelectableException e) {22 System.out.println("Element is not selectable");23 }24 }25}

Full Screen

Full Screen

ElementNotSelectableException

Using AI Code Generation

copy

Full Screen

1package com.automationstepbystep;2import org.openqa.selenium.By;3import org.openqa.selenium.ElementNotSelectableException;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.chrome.ChromeDriver;7public class ElementNotSelectableExceptionDemo {8 public static void main(String[] args) {9 System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\Downloads\\chromedriver_win32\\chromedriver.exe");10 WebDriver driver = new ChromeDriver();11 driver.manage().window().maximize();12 WebElement day = driver.findElement(By.id("day"));13 day.click();14 WebElement year = driver.findElement(By.id("year"));15 year.click();16 WebElement month = driver.findElement(By.id("month"));17 month.click();18 try {19 month.sendKeys("Mar");20 } catch (ElementNotSelectableException e) {

Full Screen

Full Screen

ElementNotSelectableException

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.*;2import org.openqa.selenium.chrome.*;3public class ElementNotSelectableException {4 public static void main(String[] args) {5 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Admin\\Desktop\\chromedriver.exe");6 WebDriver driver = new ChromeDriver();7 driver.manage().window().maximize();8 element.click();9 try {10 element.click();11 } catch (Exception e) {12 System.out.println("ElementNotSelectableException has been thrown");13 }14 driver.close();15 }16}

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful