├── README.md
├── _config.yml
└── selenium-cheat-sheet.pdf
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # A curated list of selenium commands in Java
3 |
4 | # **1. Browser property setup**
5 |
6 | - **Chrome**:
7 |
8 | ```
9 |
10 | System.setProperty(“webdriver.chrome.driver”, “/path/to/chromedriver”);
11 |
12 | ```
13 |
14 | - **Firefox:**
15 |
16 | ```
17 |
18 | System.setProperty(“webdriver.gecko.driver”, “/path/to/geckodriver”);
19 |
20 | ```
21 |
22 | - **Edge:**
23 |
24 | ```
25 |
26 | System.setProperty(“webdriver.edge.driver”, “/path/to/MicrosoftWebDriver”);
27 |
28 | ```
29 |
30 |
31 |
32 | # **2. Browser Initialization**
33 |
34 |
35 |
36 | - **Firefox**
37 |
38 | `WebDriver driver = new FirefoxDriver();`
39 |
40 |
41 |
42 | - **Chrome**
43 |
44 | `WebDriver driver = new ChromeDriver();`
45 |
46 |
47 |
48 | - **Internet Explorer**
49 |
50 | `WebDriver driver = new InternetExplorerDriver();`
51 |
52 |
53 |
54 | - **Safari Driver**
55 |
56 | `WebDriver driver = new SafariDriver();`
57 |
58 |
59 |
60 | # 3. Desired capabilities
61 |
62 |
63 |
64 | > ([**Doc link**](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/remote/DesiredCapabilities.html))
65 |
66 |
67 |
68 | - **Chrome:**
69 |
70 |
71 |
72 | ```
73 |
74 | DesiredCapabilities caps = new DesiredCapabilities();
75 | caps.setCapability(“browserName”, “chrome”);
76 | caps.setCapability(“browserVersion”, “80.0””);
77 | caps.setCapability(“platformName”, “win10”);
78 |
79 | WebDriver driver = new ChromeDriver(caps); // Pass the capabilities as an argument to the driver object
80 |
81 | ```
82 |
83 |
84 |
85 | - **Firefox:**
86 |
87 |
88 |
89 | ```
90 |
91 | DesiredCapabilities caps = new DesiredCapabilities();
92 | caps.setCapability(“browserName”, “firefox”);
93 | caps.setCapability(“browserVersion”, “81.0””);
94 | caps.setCapability(“platformName”, “win10”);
95 |
96 | WebDriver driver = new FirefoxDriver(caps); // Pass the capabilities as an argument to the driver object
97 |
98 | ```
99 |
100 |
101 |
102 | # 4. Browser options
103 |
104 | - **Chrome: ([Doc link](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/chrome/ChromeOptions.html))**
105 | ```
106 |
107 | ChromeOptions chromeOptions = new ChromeOptions();
108 | chromeOptions.setBinary("C:Program Files (x86)GoogleChromeApplicationchrome.exe"); // set if chrome is not in default location
109 | chromeOptions.addArguments("--headless"); // Passing single option
110 | chromeOptions.addArguments("--start-maximized", "--incognito","--disable-notifications" ); // Passing multiple options
111 |
112 | WebDriver driver = new ChromeDriver(chromeOptions); // Pass the capabilities as an argument to the driver object
113 |
114 | ```
115 |
116 |
117 |
118 | - **Firefox: ([Doc link](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/firefox/FirefoxOptions.html))**
119 |
120 |
121 |
122 | ```
123 |
124 | FirefoxOptions firefoxOptions = new FirefoxOptions();
125 | firefoxOptions.setBinary(new FirefoxBinary(new File("C:Program FilesMozilla Firefoxirefox.exe"))); // set if chrome is not in default location
126 | firefoxOptions.setHeadless(true);
127 |
128 | WebDriver driver = new FirefoxDriver(caps); // Pass the capabilities as an argument to the driver object
129 |
130 | ```
131 |
132 |
133 |
134 | > **Options VS Desired capabilities**:
135 | > There are two ways to specify [capabilities](https://sites.google.com/a/chromium.org/chromedriver/capabilities).
136 | > 1. **ChromeOptions/FirefoxOptions** class — Recommended
137 | > 2. Or you can specify the capabilities directly as part of the **DesiredCapabilities** — its usage in Java is deprecated
138 |
139 |
140 |
141 | # 5. Navigation
142 |
143 | - **Navigate to URL — (doc [link1](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/WebDriver.Navigation.html) [link2](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/WebDriver.html#get-java.lang.String-))**
144 |
145 |
146 |
147 | ```
148 |
149 | driver.get(“http://google.com”)
150 | driver.navigate().to(“http://google.com”)
151 |
152 | ```
153 |
154 |
155 |
156 | > **Myth** — get() method waits till the page is loaded while navigate() does not.
157 |
158 |
159 |
160 | Referring to the selenium [official doc](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/support/events/EventFiringWebDriver.html#get-java.lang.String-), get() method is a synonym for to() method. Both do the same thing.
161 |
162 |
163 |
164 | > **Myth _— _**get() does not store history while navigate() does.
165 |
166 |
167 |
168 | All the URL loaded in browser will be stored in history and navigate method allows us to access it. Try executing the below code
169 |
170 |
171 |
172 | ```
173 |
174 | driver.get(“http://madhank93.github.io/");
175 | driver.get(“https://www.google.com/");
176 | driver.navigate().back();
177 |
178 | ```
179 |
180 |
181 |
182 | - **Refresh page**
183 |
184 |
185 |
186 | ```
187 |
188 | driver.navigate().refresh()
189 |
190 | ```
191 |
192 |
193 |
194 | - **Navigate forwards in browser history**
195 |
196 |
197 |
198 | ```
199 |
200 | driver.navigate().forward()
201 |
202 | ```
203 |
204 |
205 |
206 | - **Navigate backwards in browser history**
207 |
208 |
209 |
210 | ```
211 |
212 | driver.navigate().back()
213 |
214 | ```
215 |
216 |
217 |
218 | # 6. Find element VS Find elements
219 |
220 |
221 |
222 | > ([doc link](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/WebElement.html#findElements-org.openqa.selenium.By-))
223 |
224 |
225 |
226 | - **driver.findElement()**
227 |
228 |
229 |
230 | ```
231 |
232 | When no match has found(0) throws NoSuchElementException
233 | when 1 match found returns a WebElement instance
234 | when 2 matches found returns only the first matching web element
235 |
236 | ```
237 |
238 |
239 |
240 | - **driver.findElements()**
241 |
242 |
243 |
244 | ```
245 |
246 | when no macth has found (0) returns an empty list
247 | when 1 match found returns a list with one WebElement
248 | when 2+ matches found returns a list with all matching WebElements
249 |
250 | ```
251 |
252 |
253 |
254 | # 7. Locator Strategy
255 |
256 |
257 |
258 | > ([doc link](https://www.selenium.dev/selenium/docs/api/java/))
259 |
260 |
261 |
262 | - **_By id_**
263 |
264 |
265 |
266 | ```
267 |
268 |
269 |
270 | ```
271 |
272 |
273 |
274 | `element = driver.findElement(By.id(“login”))`
275 |
276 |
277 |
278 | - **_By Class Name_**
279 |
280 |
281 |
282 | ```
283 |
284 |
285 |
286 | ```
287 |
288 |
289 |
290 | `element = driver.findElement(By.className(“Content”));`
291 |
292 |
293 |
294 | - **_By Name_**
295 |
296 |
297 |
298 | ```
299 |
300 |
301 |
302 | ```
303 |
304 |
305 |
306 | `element = driver.findElement(By.name(“pswd”));`
307 |
308 |
309 |
310 | - **_By Tag Name_**
311 |
312 |
313 |
314 | ```
315 |
316 |
…
317 |
318 | ```
319 |
320 |
321 |
322 | `element = driver.findElement(By.tagName(“div”));`
323 |
324 |
325 |
326 | - **_By Link Text_**
327 |
328 |
329 |
330 | ```
331 |
332 | News
333 |
334 | ```
335 |
336 |
337 |
338 | `element = driver.findElement(By.linkText(“News”));`
339 |
340 |
341 |
342 | - **_By XPath_**
343 |
344 |
345 |
346 | ```
347 |
348 |
353 |
354 | ```
355 |
356 |
357 |
358 | `element = driver.findElement(By.xpath(“//input[[@placeholder](http://twitter.com/placeholder)=’Username’]”));`
359 |
360 |
361 |
362 | `List of Keywords — and, or, contains(), starts-with(), text(), last()`
363 |
364 |
365 |
366 | - **_By CSS Selector_**
367 |
368 |
369 | ```
370 |
371 |
375 |
376 | ```
377 |
378 |
379 |
380 | `element = driver.findElement(By.cssSelector(“input.username”));`
381 |
382 |
383 |
384 | # 8. Click on an element
385 |
386 |
387 |
388 | - **click()** — method is used to click on en element
389 |
390 |
391 |
392 | `driver.findElement(By.className("Content")).click();`
393 |
394 |
395 |
396 | # 9. Write text inside an element — _input and textarea_
397 |
398 |
399 |
400 | - **sendKeys()** — method is used to send data
401 |
402 |
403 |
404 | `driver.findElement(By.className("email")).sendKeys(“abc@xyz.com”);`
405 |
406 |
407 |
408 | # 10. Clear text from text box
409 |
410 |
411 |
412 | - **clear()** — method is used to clear text from text area
413 |
414 |
415 |
416 | `driver.findElement(By.xpath(“//input[[@placeholder](http://twitter.com/placeholder)=’Username’]”)).clear();`
417 |
418 |
419 |
420 | # **11. Select a drop-down**
421 |
422 |
423 |
424 | > ([doc link](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/support/ui/Select.html))
425 |
426 |
427 |
428 | ```
429 |
430 | // single select option
431 |
432 | `
437 |
438 |
439 |
440 | // multiple select option
441 |
442 |
448 |
449 | ```
450 |
451 |
452 |
453 | - **selectByVisibleText() / selectByValue() / selectByIndex()**
454 |
455 |
456 |
457 | - **deselectByVisibleText() / deselectByValue() / deselectByIndex()**
458 |
459 |
460 |
461 | ```
462 |
463 | // import statements for select class
464 |
465 | import org.openqa.selenium.support.ui.Select;
466 |
467 |
468 |
469 | // Single selection
470 |
471 | Select country = new Select(driver.findElement(By.id("country")));
472 | country.selectByVisibleText("Canada"); // using selectByVisibleText() method
473 | country.selectByValue("MX"); //using selectByValue() method
474 |
475 |
476 |
477 | //Selecting Items in a Multiple SELECT elements
478 |
479 | Select fruits = new Select(driver.findElement(By.id("fruits")));
480 | fruits.selectByVisibleText("Banana");
481 | fruits.selectByIndex(1); // using selectByIndex() method
482 |
483 | ```
484 |
485 |
486 |
487 | # **12. Get methods in Selenium**
488 |
489 |
490 |
491 | - **getTitle()**—used to retrieve the current title of the webpage
492 |
493 |
494 |
495 | - **getCurrentUrl()** — used to retrieve the current URL of the webpage
496 |
497 |
498 |
499 | - **getPageSource()** — used to retrieve the current page source
500 |
501 | of the webpage
502 |
503 |
504 |
505 | - **getText()** — used to retrieve the text of the specified web element
506 |
507 |
508 |
509 | - **getAttribute()** —used to retrieve the value specified in the attribute
510 |
511 |
512 |
513 | # 13. Handle alerts: (Web based alert pop-ups)
514 |
515 |
516 |
517 | - **driver.switchTO().alert.getText()** — to retrieve the alert message
518 |
519 |
520 |
521 | - **driver.switchTO().alert.accept()** — to accept the alert box
522 |
523 |
524 |
525 | - **driver.switchTO().alert.dismiss()** — to cancel the alert box
526 |
527 |
528 |
529 | - **driver.switchTO().alert.sendKeys(“Text”)** — to send data to the alert box
530 |
531 |
532 |
533 | # 14. Switch frames
534 |
535 |
536 |
537 | - **driver.switchTo.frame(int frameNumber)** — mentioning the frame index number, the Driver will switch to that specific frame
538 |
539 |
540 |
541 | - **driver.switchTo.frame(string frameNameOrID)** — mentioning the frame element or ID, the Driver will switch to that specific frame
542 |
543 |
544 |
545 | - **driver.switchTo.frame(WebElement frameElement)** — mentioning the frame web element, the Driver will switch to that specific frame
546 |
547 |
548 |
549 | - **driver.switchTo().defaultContent()** — Switching back to the main window
550 |
551 |
552 |
553 | # **15. Handle multiple windows and tabs**
554 |
555 |
556 |
557 | - **getWindowHandle()** — used to retrieve handle of the current page (a unique identifier)
558 |
559 |
560 |
561 | - **getWindowHandles()** — used to retrieve a set of handles of the all the pages available
562 |
563 |
564 |
565 | - **driver.switchTo().window(“windowName/handle”)** — switch to a window
566 |
567 |
568 |
569 | - **driver.close()** — closes the current browser window
570 |
571 |
572 |
573 | # 16. Waits in selenium
574 |
575 |
576 |
577 | There are 3 types of waits in selenium,
578 |
579 |
580 |
581 | - **Implicit Wait**—used to wait for a certain amount of time before throwing an exception
582 |
583 |
584 |
585 | ```
586 |
587 | driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
588 |
589 | ```
590 |
591 |
592 |
593 | - **Explicit Wait** — used to wait until a certain condition occurs before executing the code.
594 |
595 |
596 |
597 | ```
598 |
599 | WebDriverWait wait = new WebDriverWait(driver,30);
600 | wait.until(ExpectedConditions.presenceOfElementLocated(By.name("login")));
601 |
602 | ```
603 |
604 |
605 |
606 | **List of explicit wait:**
607 |
608 |
609 |
610 | ```
611 |
612 | alertIsPresent()
613 | elementSelectionStateToBe()
614 | elementToBeClickable()
615 | elementToBeSelected()
616 | frameToBeAvaliableAndSwitchToIt()
617 | invisibilityOfTheElementLocated()
618 | invisibilityOfElementWithText()
619 | presenceOfAllElementsLocatedBy()
620 | presenceOfElementLocated()
621 | textToBePresentInElement()
622 | textToBePresentInElementLocated()
623 | textToBePresentInElementValue()
624 | titleIs()
625 | titleContains()
626 | visibilityOf()
627 | visibilityOfAllElements()
628 | visibilityOfAllElementsLocatedBy()
629 | visibilityOfElementLocated()
630 |
631 | ```
632 |
633 |
634 |
635 | - **Fluent Wait** — defines the maximum amount of time to wait for a certain condition to appear
636 |
637 |
638 |
639 | ```
640 |
641 | Wait wait = new FluentWait(WebDriver reference)
642 | .withTimeout(Duration.ofSeconds(SECONDS))
643 | .pollingEvery(Duration.ofSeconds(SECONDS))
644 | .ignoring(Exception.class);
645 |
646 | WebElement foo=wait.until(new Function() {
647 | public WebElement apply(WebDriver driver) {
648 | return driver.findElement(By.id("foo"));
649 | }
650 | });
651 |
652 | ```
653 |
654 |
655 |
656 | # 17. Element validation
657 |
658 |
659 |
660 | - [**isEnabled()**](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/WebElement.html#isEnabled--) — determines if an element is enabled or not, returns a boolean.
661 |
662 |
663 |
664 | - [**isSelected()**](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/WebElement.html#isSelected--) — determines if an element is selected or not, returns a boolean.
665 |
666 |
667 |
668 | - [**isDisplayed()**](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/WebElement.html#isDisplayed--) — determines if an element is displayed or not, returns a boolean.
669 |
670 |
671 |
672 | # 18. Handling proxy
673 |
674 |
675 |
676 | - **Chrome:**
677 |
678 |
679 |
680 | ```
681 |
682 | ChromeOptions options = new ChromeOptions();
683 |
684 | // Create object Proxy class - Approach 1
685 | Proxy proxy = new Proxy();
686 | proxy.setHttpProxy("username:password.myhttpproxy:3337");
687 |
688 | // register the proxy with options class - Approach 1
689 | options.setCapability("proxy", proxy);
690 |
691 | // Add a ChromeDriver-specific capability.
692 | ChromeDriver driver = new ChromeDriver(options);
693 |
694 | ```
695 |
696 |
697 |
698 | - **Firefox:**
699 |
700 |
701 |
702 | ```
703 |
704 | FirefoxOptions options = new FirefoxOptions();
705 |
706 | // Create object Proxy class - Approach 2
707 | Proxy proxy = new Proxy();
708 | proxy.setHttpProxy("myhttpproxy:3337");
709 | proxy.setSocksUsername("username");
710 | proxy.setSocksPassword("password")
711 |
712 | // register the proxy with options class - Approach 2
713 | options.setProxy(proxy);
714 |
715 | // create object to firefx driver
716 | WebDriver driver = new FirefoxDriver(options);
717 |
718 | ```
719 |
720 |
721 |
722 | # 19. Window management
723 |
724 |
725 |
726 | - **Get window size:**
727 |
728 |
729 |
730 | ```
731 |
732 | //Access each dimension individually
733 | int width = driver.manage().window().getSize().getWidth();
734 | int height = driver.manage().window().getSize().getHeight();
735 |
736 |
737 |
738 | //Or store the dimensions and query them later
739 | Dimension size = driver.manage().window().getSize();
740 | int width1 = size.getWidth();
741 | int height1 = size.getHeight();`
742 |
743 | ```
744 |
745 |
746 |
747 | - **Set window size:**
748 |
749 |
750 |
751 | ```
752 |
753 | driver.manage().window().setSize(new Dimension(1024, 768));`
754 |
755 | ```
756 |
757 |
758 |
759 | - **Get window position:**
760 |
761 |
762 |
763 | ```
764 |
765 | // Access each dimension individually
766 | int x = driver.manage().window().getPosition().getX();
767 | int y = driver.manage().window().getPosition().getY();
768 |
769 | // Or store the dimensions and query them later
770 | Point position = driver.manage().window().getPosition();
771 |
772 | int x1 = position.getX();
773 | int y1 = position.getY();`
774 |
775 | ```
776 |
777 |
778 |
779 | - **Set window position:**
780 |
781 |
782 |
783 | ```
784 |
785 | // Move the window to the top left of the primary monitor
786 | driver.manage().window().setPosition(new Point(0, 0));`
787 |
788 | ```
789 |
790 |
791 |
792 | - **Maximise window:**
793 |
794 |
795 |
796 | ```
797 |
798 | driver.manage().window().minimize();
799 |
800 | ```
801 |
802 | - **Fullscreen window:**
803 |
804 | ```
805 |
806 | driver.manage().window().fullscreen();
807 |
808 | ```
809 |
810 | # 20. Page loading strategy
811 |
812 |
813 |
814 | The `document.readyState` property of a document describes the loading state of the current document. By default, WebDriver will hold off on responding to a `driver.get()` (or) `driver.navigate().to()` call until the document ready state is `complete`
815 |
816 |
817 |
818 | By default, when Selenium WebDriver loads a page, it follows the normal pageLoadStrategy.
819 |
820 |
821 |
822 | - **normal:**
823 |
824 |
825 |
826 | ```
827 |
828 | ChromeOptions chromeOptions = new ChromeOptions();
829 | chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
830 | WebDriver driver = new ChromeDriver(chromeOptions);
831 |
832 | ```
833 |
834 |
835 |
836 | - **eager:** When set to eager, Selenium WebDriver waits until [DOMContentLoaded](https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event) event fire is returned.
837 |
838 |
839 |
840 | ```
841 |
842 | ChromeOptions chromeOptions = new ChromeOptions();
843 | chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
844 | WebDriver driver = new ChromeDriver(chromeOptions);
845 |
846 | ```
847 |
848 |
849 |
850 | - **none:** When set to none Selenium WebDriver only waits until the initial page is downloaded.
851 |
852 |
853 |
854 | ```
855 |
856 | ChromeOptions chromeOptions = new ChromeOptions();
857 | chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
858 | WebDriver driver = new ChromeDriver(chromeOptions);
859 |
860 | ```
861 |
862 |
863 |
864 | # **21. Keyboard and Mouse events**
865 |
866 |
867 |
868 | [Action class](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/interactions/Actions.html) is used to handle keyboard and mouse events
869 |
870 |
871 |
872 | #### **keyboard events:**
873 |
874 |
875 |
876 | - keyDown()
877 | - keyUp()
878 | - sendKeys()
879 |
880 |
881 |
882 | #### Mouse events:
883 |
884 |
885 |
886 | - clickAndHold()
887 | - contextClick() — peforms the mouse right click action
888 | - doubleClick()
889 | - dragAndDrop(source,target)
890 | - dragAndDropBy(source,xOffset,yOffset)
891 | - moveByOffset(xOffset,yOffset)
892 | - moveByElement()
893 | - release()
894 |
895 |
896 |
897 | ```
898 |
899 | Actions builder = new Actions(driver);
900 |
901 | Action actions = builder
902 | .moveToElement("login-textbox")
903 | .click()
904 | .keyDown("login-textbox", Keys.SHIFT)
905 | .sendKeys("login-textbox", "hello")
906 | .keyUp("login-textbox", Keys.SHIFT)
907 | .doubleClick("login-textbox")
908 | .contextClick()
909 | .build();
910 |
911 | actions.perform();
912 |
913 | ```
914 |
915 |
916 |
917 | # 22. Cookies
918 |
919 |
920 |
921 | - **addCookie(arg)**
922 |
923 |
924 |
925 | ```
926 |
927 | driver.manage().addCookie(new Cookie("foo", "bar"));
928 |
929 | ```
930 |
931 |
932 | - **getCookies()**
933 |
934 |
935 | ```
936 |
937 | driver.manage().getCookies(); // to get all cookies
938 |
939 | ```
940 |
941 | - **getCookieNamed()**
942 |
943 | ```
944 |
945 | driver.manage().getCookieNamed("foo");
946 |
947 | ```
948 |
949 |
950 |
951 | - **deleteCookieNamed()**
952 |
953 | ```
954 |
955 | driver.manage().deleteCookieNamed("foo");
956 |
957 | ```
958 |
959 | - **deleteCookie()**
960 |
961 | ```
962 |
963 | Cookie cookie1 = new Cookie("test2", "cookie2");
964 | driver.manage().addCookie(cookie1);
965 |
966 | driver.manage().deleteCookie(cookie1); // deleting cookie object`
967 |
968 | ```
969 |
970 |
971 |
972 | - **deleteAllCookies()**
973 |
974 |
975 |
976 | ```
977 |
978 | driver.manage().deleteAllCookies(); // deletes all cookies`
979 |
980 | ```
981 |
982 |
983 |
984 | # 23. Take screenshot:
985 |
986 |
987 |
988 | > [(doc link)](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/TakesScreenshot.html)
989 |
990 |
991 |
992 | - **getScreenshotAs** — used to Capture the screenshot and store it in the specified location. This method throws WebDriverException. copy() method from [File Handler](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/io/FileHandler.html) class is used to store the screeshot in a destination folder
993 |
994 |
995 |
996 | ```
997 |
998 | TakesScreenshot screenShot =(TakesScreenshot)driver;
999 |
1000 | FileHandler.copy(screenShot.getScreenshotAs(OutputType.FILE), new File("path/to/destination/folder/screenshot.png"));
1001 |
1002 | ```
1003 |
1004 |
1005 |
1006 | # **24. Execute Javascript:**
1007 |
1008 |
1009 |
1010 | > [(doc link)](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/JavascriptExecutor.html)
1011 |
1012 |
1013 |
1014 | - **executeAsyncScript()** — executes an asynchronous piece of JavaScript
1015 |
1016 |
1017 |
1018 | - **executeScript()** — executes JavaScript
1019 |
1020 |
1021 |
1022 | ```
1023 |
1024 | if (driver instanceof JavascriptExecutor) {
1025 |
1026 | ((JavascriptExecutor)driver).executeScript("alert('hello world');");
1027 |
1028 | }
1029 |
1030 | ```
1031 |
1032 |
1033 |
1034 | ---
1035 |
1036 |
1037 |
1038 | _Last updated on — Apr 18, 2020_
1039 |
1040 |
1041 |
1042 | # References:
1043 |
1044 |
1045 |
1046 | [1][https://www.selenium.dev/selenium/docs/api/java/overview-summary.html](https://www.selenium.dev/selenium/docs/api/java/overview-summary.html)
1047 |
1048 |
1049 |
1050 | [2][https://www.selenium.dev/documentation/en/](https://www.selenium.dev/documentation/en/)
1051 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-cayman
2 |
--------------------------------------------------------------------------------
/selenium-cheat-sheet.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madhank93/selenium-cheatsheet-java/25ef725f8f25fe5bbbddb691fb57250eaf263480/selenium-cheat-sheet.pdf
--------------------------------------------------------------------------------