\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Narayanan Palani (Narayanan Palani)} \pdfinfo{ /Title (selenium-webdriver-cheat-sheet.pdf) /Creator (Cheatography) /Author (Narayanan Palani (Narayanan Palani)) /Subject (Selenium WebDriver Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{ABABAB} \definecolor{LightBackground}{HTML}{F4F4F4} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Selenium WebDriver Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Narayanan Palani (Narayanan Palani)} via \textcolor{DarkBackground}{\uline{cheatography.com/32112/cs/9838/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Narayanan Palani (Narayanan Palani) \\ \uline{cheatography.com/narayanan-palani} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 15th November, 2016.\\ Updated 23rd October, 2020.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Driver Initialization}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Firefox}} ({\emph{Below v.47}})\textasciicircum{}Refer Part2-Page58\textasciicircum{} & \seqsplit{System.setProperty("webdriver.gecko.driver"}, "PathTo\textbackslash{}\textbackslash{}geckodriver.exe"); \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Download from \seqsplit{https://github.com/mozilla/geckodriver/releases} & WebDriver driver = new FirefoxDriver(); \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} {\bf{Chrome}}\textasciicircum{}Refer Part2-Page59\textasciicircum{} & \seqsplit{System.setProperty("WebDriver.chrome.driver"}, \seqsplit{System.getProperty("user.dir")+"//BrowserDrivers//chromedriver.exe");} \tn % Row Count 14 (+ 6) % Row 3 \SetRowColor{white} Download from \seqsplit{https://sites.google.com/a/chromium.org/chromedriver/downloads} & WebDriver driver = new ChromeDriver(); \tn % Row Count 18 (+ 4) % Row 4 \SetRowColor{LightBackground} {\bf{Internet Explorer}}\textasciicircum{}Refer Part2-Page59\textasciicircum{} & \seqsplit{System.setProperty("WebDriver.ie.driver"}, \seqsplit{"PathTo//IEDriverServer}.exe"); \tn % Row Count 22 (+ 4) % Row 5 \SetRowColor{white} Download from The Internet Explorer Driver Server at \seqsplit{http://docs.seleniumhq.org/download/} & WebDriver driver = new \seqsplit{InternetExplorerDriver();} \tn % Row Count 27 (+ 5) % Row 6 \SetRowColor{LightBackground} {\bf{Safari Driver}} & WebDriver driver = new SafariDriver(); \tn % Row Count 29 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Selenium Locators}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Locating by ID}} \textasciicircum{}Refer Part2-Page37\textasciicircum{} & \seqsplit{driver.findElement(By.id("q")).sendKeys("Selenium} 3"); \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Locating by Name}}\textasciicircum{}Refer Part2-Page37\textasciicircum{} & \seqsplit{driver.findElement(By.name("q")).sendKeys("Selenium} 3"); \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{Locating by Xpath}}\textasciicircum{}Refer Part2-Page37/38\textasciicircum{} & \seqsplit{driver.findElement(By}.xpath("//input{[}@id='q'{]}")).sendKeys("Selenium 3"); \tn % Row Count 10 (+ 4) % Row 3 \SetRowColor{white} {\bf{Locating Hyperlinks by Link Text }}\textasciicircum{}Refer Part2-Page38/39\textasciicircum{} & \seqsplit{driver.FindElement(By.LinkText("edit} this page")).Click(); \tn % Row Count 13 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{Locating by DOM}}\textasciicircum{}Refer Part2-Page39\textasciicircum{} & dom \seqsplit{=document.getElementById('signinForm')} \tn % Row Count 16 (+ 3) % Row 5 \SetRowColor{white} {\bf{Locating by CSS}}\textasciicircum{}Refer Part2-Page40-43\textasciicircum{} & \seqsplit{driver.FindElement(By.CssSelector("\#rightbar} \textgreater{} .menu \textgreater{} li:nth-of-type(2) \textgreater{} h4")); \tn % Row Count 21 (+ 5) % Row 6 \SetRowColor{LightBackground} {\bf{Locating by ClassName}}\textasciicircum{}Refer Part2-Page37\textasciicircum{} & \seqsplit{driver.findElement(By.className("profile-header"));} \tn % Row Count 24 (+ 3) % Row 7 \SetRowColor{white} {\bf{Locating by TagName}}\textasciicircum{}Refer Part2-Page37\textasciicircum{} & \seqsplit{driver.findElement(By.tagName("select")).Click();} \tn % Row Count 27 (+ 3) % Row 8 \SetRowColor{LightBackground} {\bf{Locating by LinkText}}\textasciicircum{}Refer Part2-Page37-40\textasciicircum{} & \seqsplit{driver.findElement(By.linkText("NextPage")).click();} \tn % Row Count 30 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Selenium Locators (cont)}} \tn % Row 9 \SetRowColor{LightBackground} {\bf{Locating by PartialLinkText}}\textasciicircum{}Refer Part2-Page37-40\textasciicircum{} & \seqsplit{driver.findElement(By.partialLinkText("NextP")).click();} \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{ISTQB Advanced Test Automation Engineering}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{8.4cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/narayanan-palani_1603438729_EngineersHub_Banner.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\seqsplit{https://engineers-hub.teachable.com/p/istqb-advanced-level-test-automation-engineer-professional-training-with-q-a}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Selenium Q\&A}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{8.4cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/narayanan-palani_1592682827_Certified Selenium Tester Foundations_Udemy_NoCode.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\seqsplit{https://www.udemy.com/course/certified-selenium-tester-foundation/}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Find element VS Find elements}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{driver.findElement()}} & When no match has found(0) throws NoSuchElementException when 1 match found returns a WebElement instance when 2+ matches found returns only the first matching web element \tn % Row Count 8 (+ 8) % Row 1 \SetRowColor{white} {\bf{driver.findElements()}} & when no macth has found (0) returns an empty list when 1 match found returns a list with one WebElement when 2+ matches found returns a list with all matching WebElements \tn % Row Count 16 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.64 cm} x{3.36 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Handle alerts: (Web-based alert pop-ups)}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{driver.switchTO().alert.getText()}} & to retrieve the alert message \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{driver.switchTO().alert.accept() }} & to accept the alert box \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{driver.switchTO().alert.dismiss()}} & to cancel the alert box \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{driver.switchTO().alert.sendKeys("Text") }} & to send data to the alert box \tn % Row Count 9 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Page Loading Strategy}} \tn % Row 0 \SetRowColor{LightBackground} normal & ChromeOptions chromeOptions = new ChromeOptions(); \seqsplit{chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);} WebDriver driver = new \seqsplit{ChromeDriver(chromeOptions);} \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} eager: When setting to eager, Selenium WebDriver waits until DOMContentLoaded event fire is returned. & ChromeOptions chromeOptions = new ChromeOptions(); \seqsplit{chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);} WebDriver driver = new \seqsplit{ChromeDriver(chromeOptions);} \tn % Row Count 18 (+ 9) % Row 2 \SetRowColor{LightBackground} none: When set to none Selenium WebDriver only waits until the initial page is downloaded. & ChromeOptions chromeOptions = new ChromeOptions(); \seqsplit{chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);} WebDriver driver = new \seqsplit{ChromeDriver(chromeOptions);} \tn % Row Count 26 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{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 \newline By default, when Selenium WebDriver loads a page, it follows the normal pageLoadStrategy.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.96 cm} x{5.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Cookies}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{addCookie(arg)}} & \seqsplit{driver.manage().addCookie(new} Cookie("foo", "bar")); \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{getCookies()}} & \seqsplit{driver.manage().getCookies();} // to get all cookies \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{getCookieNamed()}} & \seqsplit{driver.manage().getCookieNamed("foo");} \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} {\bf{deleteCookieNamed()}} & \seqsplit{driver.manage().deleteCookieNamed("foo");} \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{deleteCookie()}} & Cookie cookie1 = new Cookie("test2", "cookie2"); \seqsplit{driver.manage().addCookie(cookie1);} driver.manage().deleteCookie(cookie1); // deleting cookie object \tn % Row Count 16 (+ 6) % Row 5 \SetRowColor{white} {\bf{deleteAllCookies()}} & \seqsplit{driver.manage().deleteAllCookies();} // deletes all cookies \tn % Row Count 19 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{5.44 cm} x{2.56 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Take screenshot}} \tn % Row 0 \SetRowColor{LightBackground} Capture the screenshot and store & \seqsplit{getScreenshotAs} \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{getScreenshotAs — used to Capture the screenshot and store it in the specified location. This method throws WebDriverException. copy() method from the File Handler class is used to store the screenshot in a destination folder. \newline Code Example: \newline TakesScreenshot screenShot \seqsplit{=(TakesScreenshot)driver;} \newline FileHandler.copy(screenShot.getScreenshotAs(OutputType.FILE), new \seqsplit{File("path/to/destination/folder/screenshot}.png"));} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{5.36 cm} x{2.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Execute Javascript}} \tn % Row 0 \SetRowColor{LightBackground} Executes an asynchronous piece of JavaScript & \seqsplit{executeAsyncScript()} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Executes JavaScript & \seqsplit{executeScript()} \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Code Example: \newline if (driver instanceof JavascriptExecutor) \{ \newline \seqsplit{((JavascriptExecutor)driver)}.executeScript("alert('hello world');"); \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{1.04 cm} x{6.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Annotations}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{TestNG} & @BeforeSuite @AfterSuite @BeforeTest @AfterTest @BeforeGroups @AfterGroups @BeforeClass @AfterClass @BeforeMethod @AfterMethod \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} JUnit & @After @AfterClass @Before @BeforeClass @Ignore @Test \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Selenium Exceptions}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{'Server Exception : sessionId should not be null}}\textasciicircum{}Refer Part2-Page160\textasciicircum{} & Replace Chrome Driver with Latest Version \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} {\bf{ERROR: No sessionId provided}}\textasciicircum{}Refer Part2-Page160\textasciicircum{} & Use Jenkins \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{UnreachableBrowserException}}\textasciicircum{}Refer Part2-Page160\textasciicircum{} & Registry Key Changes Recommended \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} {\bf{Illegal state exception using Selenium 3}}\textasciicircum{}Refer Part2-Page161\textasciicircum{} & Get latest Firefox Gecko Driver \tn % Row Count 14 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.16 cm} x{5.84 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Keyboard and Mouse events}} \tn % Row 0 \SetRowColor{LightBackground} keyboard events & keyDown(); keyUp(); sendKeys() \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Mouse events & clickAndHold(); contextClick()// — performs the mouse right-click action; doubleClick(); dragAndDrop(source,target); dragAndDropBy(source,xOffset,yOffset); moveByOffset(xOffset,yOffset); moveByElement(); release() \tn % Row Count 10 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Code Example: \newline Actions builder = new Actions(driver); \newline Action actions = builder \newline \seqsplit{.moveToElement("login-textbox")} \newline .click() \newline .keyDown("login-textbox", Keys.SHIFT) \newline \seqsplit{.sendKeys("login-textbox"}, "hello") \newline .keyUp("login-textbox", Keys.SHIFT) \newline \seqsplit{.doubleClick("login-textbox")} \newline .contextClick() \newline .build(); \newline \newline actions.perform() ;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.4 cm} x{5.6 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Element validation}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{isEnabled()}} & determines if an element is enabled or not, returns a boolean. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{isSelected()}} & determines if an element is selected or not, returns a boolean. \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{isDisplayed()}} & determines if an element is displayed or not, returns a boolean. \tn % Row Count 9 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Handle multiple windows and tabs}} \tn % Row 0 \SetRowColor{LightBackground} getWindowHandle() & used to retrieve the handle of the current page (a unique identifier) \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} getWindowHandles() & used to retrieve a set of handles of the all the pages available \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} \seqsplit{driver.switchTo().window("windowName/handle")} & switch to a window \tn % Row Count 11 (+ 3) % Row 3 \SetRowColor{white} driver.close() & closes the current browser window \tn % Row Count 13 (+ 2) % Row 4 \SetRowColor{LightBackground} driver.quit(); & This method Closes all windows opened by the WebDriver. \tn % Row Count 16 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Switch Frames}} \tn % Row 0 \SetRowColor{LightBackground} Mentioning the frame index number, the Driver will switch to that specific frame & {\bf{driver.switchTo.frame(int frameNumber)}} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Mentioning the frame element or ID, the Driver will switch to that specific frame & {\bf{driver.switchTo.frame(string frameNameOrID)}} \tn % Row Count 9 (+ 5) % Row 2 \SetRowColor{LightBackground} Mentioning the frame web element, the Driver will switch to that specific frame & {\bf{driver.switchTo.frame(WebElement frameElement)}} \tn % Row Count 13 (+ 4) % Row 3 \SetRowColor{white} Switching back to the main window & {\bf{driver.switchTo().defaultContent()}} \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Materials}} \tn % Row 0 \SetRowColor{LightBackground} Selenium Certification & \seqsplit{https://isqi.org/en/54-certified-selenium-tester-foundation.html} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Selenium Certification Q\&A & \seqsplit{https://engineers-hub}.teachable.com/ \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} Part1-Software Automation Testing Secrets Revealed & \seqsplit{https://www.amazon.com/Software-Automation-Testing-Secrets-Revealed/dp/1729432506/} \tn % Row Count 11 (+ 5) % Row 3 \SetRowColor{white} Part2-Software Automation Testing Secrets Revealed & \seqsplit{https://www.amazon.com/gp/product/1729432379/} \tn % Row Count 14 (+ 3) % Row 4 \SetRowColor{LightBackground} Part3-Software Automation Testing Secrets Revealed & \seqsplit{https://www.amazon.com/Advanced-Selenium-Web-Accessibility-Testing/dp/1949449432/} \tn % Row Count 19 (+ 5) % Row 5 \SetRowColor{white} Udemy Course-Selenium & \seqsplit{https://engineers-hub}.teachable.com/ \tn % Row Count 21 (+ 2) % Row 6 \SetRowColor{LightBackground} Udemy Course-ISTQB Test Automation Engineering & \seqsplit{https://engineers-hub}.teachable.com/ \tn % Row Count 24 (+ 3) % Row 7 \SetRowColor{white} Useful Commands (Credits: Madhan K) & \seqsplit{https://medium.com/@madhankumaravelu93/selenium-cheat-sheet-a-comprehensive-list-of-selenium-commands-fa4c5c9d11ab} \tn % Row Count 30 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Materials (cont)}} \tn % Row 8 \SetRowColor{LightBackground} Useful Commands (Credits: Bijan Patel) & \seqsplit{https://qascript.com/selenium-webdriver-commands-cheat-sheet/} \tn % Row Count 4 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.56 cm} x{5.44 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Get methods in Selenium}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{getTitle()}} & used to retrieve the current title of the webpage \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{getCurrentUrl()}} & used to retrieve the current URL of the webpage \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{getPageSource()}} & used to retrieve the current page source of the webpage \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} {\bf{getText() }} & used to retrieve the text of the specified web element \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{getAttribute()}} & used to retrieve the value specified in the attribute \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.48 cm} x{3.52 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Navigation}} \tn % Row 0 \SetRowColor{LightBackground} Refresh Page & {\bf{driver.navigate().refresh()}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Navigate forwards in the browser history & {\bf{driver.navigate().forward()}} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Navigate backward in the browser history & {\bf{driver.navigate().back()}} \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Desired Capabilities-Chrome}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{DesiredCapabilities caps = new DesiredCapabilities(); \seqsplit{caps.setCapability("browserName"}, "chrome"); \seqsplit{caps.setCapability("browserVersion"}, "80.0""); \seqsplit{caps.setCapability("platformName"}, "win10"); \newline WebDriver driver = new ChromeDriver(caps); // Pass the capabilities as an argument to the driver object} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Desired Capabilities-Firefox}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{DesiredCapabilities caps = new DesiredCapabilities(); \seqsplit{caps.setCapability("browserName"}, "firefox"); \seqsplit{caps.setCapability("browserVersion"}, "81.0""); \seqsplit{caps.setCapability("platformName"}, "win10"); \newline WebDriver driver = new FirefoxDriver(caps); // Pass the capabilities as an argument to the driver object} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Practice Scripts}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Launch Webpage}}\textasciicircum{}Refer Part2-Page60\textasciicircum{} & \seqsplit{driver.get("www.webdriverinselenium.com");} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Click Button}}\textasciicircum{}Refer Part2-Page60\textasciicircum{} & \seqsplit{driver.findElement(By.id("submit")).click();} \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{Store Text}}\textasciicircum{}Refer Part2-Page60\textasciicircum{} & String txtDropdown = \seqsplit{driver.findElement(By.ID("select")).getText();} \tn % Row Count 10 (+ 4) % Row 3 \SetRowColor{white} {\bf{Enter Text}}\textasciicircum{}Refer Part2-Page61\textasciicircum{} & \seqsplit{driver.findElement(By}.xpath("//input{[}@name='FirstName034'{]}")).sendKeys("NarayananPalani"); \tn % Row Count 15 (+ 5) % Row 4 \SetRowColor{LightBackground} {\bf{Handle Alert}}\textasciicircum{}Refer Part2-Page62\textasciicircum{} & Alert Alertpopup = \seqsplit{driver.switchTo().alert();} \tn % Row Count 18 (+ 3) % Row 5 \SetRowColor{white} {\bf{(Mouse)Click}}\textasciicircum{}Refer Part2-Page62\textasciicircum{} & \seqsplit{driver.findElement(By}.xpath("//input{[}@value='OBJECT NAME'{]}")).click(); \tn % Row Count 22 (+ 4) % Row 6 \SetRowColor{LightBackground} {\bf{Compare Text}}\textasciicircum{}Refer Part2-Page64\textasciicircum{} & \seqsplit{Assert.assertTrue(chkbox12.isSelected());} \tn % Row Count 25 (+ 3) % Row 7 \SetRowColor{white} {\bf{Disable a Field}}\textasciicircum{}Refer Part2-Page64\textasciicircum{} & driver.getElementsByName('\textless{}ObjectID\textgreater{}'){[}0{]}.setAttribute('disabled', ''); \tn % Row Count 29 (+ 4) % Row 8 \SetRowColor{LightBackground} {\bf{Enable a Field}}\textasciicircum{}Refer Part2-Page64\textasciicircum{} & driver.getElementsByName('\textless{}ObjectID\textgreater{}'){[}0{]}.removeAttribute('disabled'; \tn % Row Count 33 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Practice Scripts (cont)}} \tn % Row 9 \SetRowColor{LightBackground} {\bf{Screenshot}}\textasciicircum{}Refer Part2-Page64\textasciicircum{} & File snapshot = \seqsplit{((TakesScreenshot)driver)}.getScreenshotAs(OutputType.FILE); \tn % Row Count 4 (+ 4) % Row 10 \SetRowColor{white} & \seqsplit{FileUtils.copyFile(snapshot}, new File("C:\textbackslash{}\textbackslash{}screenshot.jpg")); \tn % Row Count 8 (+ 4) % Row 11 \SetRowColor{LightBackground} {\bf{Print the Title of the Page}}\textasciicircum{}Refer Part2-Page68\textasciicircum{} & String pagetitle = driver.getTitle(); \tn % Row Count 11 (+ 3) % Row 12 \SetRowColor{white} & \seqsplit{System.out.print(pagetitle);} \tn % Row Count 13 (+ 2) % Row 13 \SetRowColor{LightBackground} {\bf{Implicit Wait}}\textasciicircum{}Refer Part2-Page69\textasciicircum{} & \seqsplit{driver.manage().timeouts().implicitlyWait(10}, TimeUnit.SECONDS); \tn % Row Count 17 (+ 4) % Row 14 \SetRowColor{white} {\bf{Explicit Wait}}\textasciicircum{}Refer Part2-Page70\textasciicircum{} & WebDriverWait wait = new \seqsplit{WebDriverWait(driver}, 20); \tn % Row Count 20 (+ 3) % Row 15 \SetRowColor{LightBackground} & \seqsplit{wait.until(ExpectedConditions.textToBePresentInElementLocated(By}.xpath("//div{[}@id='\textless{}Object ID\textgreater{}'{]}"), "Enter Your Personal Details")); \tn % Row Count 27 (+ 7) % Row 16 \SetRowColor{white} {\bf{Fluent Wait}}\textasciicircum{}Refer Part2-Page70\textasciicircum{} & Wait wait = new FluentWait(driver) \tn % Row Count 29 (+ 2) % Row 17 \SetRowColor{LightBackground} & .withTimeout(20, SECONDS) \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Practice Scripts (cont)}} \tn % Row 18 \SetRowColor{LightBackground} {\bf{Sleep}}\textasciicircum{}Refer Part2-Page70\textasciicircum{} & Thread.Sleep(10); \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}