Uploaded on Jun 2, 2022
DevLabs_Alliance_Top 20 Advanced Selenium Interview Questions for SDET
DevLabs_Alliance_Top 20 Advanced Selenium Interview Questions for SDET
Top20AdvancedSelenium
InterviewQuestionsforSDET
ByDevLabsAlliance
Visit us
at:www.devlabsalliance.
com Email:training@devla
bsalliance.com Contact:
+ 919717514555
AdvancedSeleniumInterviewQuestionsforSDET
1. Whatwillhappenifyoumixbothimplicitwait and explicitwaitina
SeleniumScript?
According totheofficialSeleniumdocuments,itis
beingsuggestedtonottomixbothImplicitand ExplicitWaits.Ifwemix
bothofthemthenitcancauseunpredictablewaittimes.
Implicitwaitisdefinedonlyonceinthecodeand itwillremainsamethroughoutthe
driverobject instance.
Explicitwaitisdefinedwhereveritisnecessaryinthecodeanditwillcalledatthetimeof
execution.
Explicitwaitwilloverwritetheimplicitwaitifappliedinthecode.So,ExplicitWaitalways
getsfirst preferenceandthethenImplicit Waitis executed.
AdvancedSeleniumInterviewQuestionsforSDET
2. What willhappenif yourunthiscommand.
driver.get(“www.devlabsalliance.com”);
Since the given URL doesn’t contain http or https prefix hence it will throw an
exception.So,itisrequiredto passHTTPor
HTTPSprotocolwithindriver.get()method.driver.get(“https://www.devlabsalliance.com”)
;
AdvancedSeleniumInterviewQuestionsforSDET
3. WhatisMaxInstancesPropertiesinSeleniumGrid?
MaxInstancesisdefinedasthe numberofbrowserinstancesofthe sameversionofthe
browserthatcanrunontheremotemachine.fore
g.
-browser
browserName=InternetExplorer,version=11,maxInstances=3,platform=WINDOWS
-browserbrowserName=Firefox,version=12,maxInstances=2,platform=WINDOWS
This willallowtorun5instances(3instancesofIEand2instancesofFirefox)atthesame
timeinaremote machine.
AdvancedSeleniumInterviewQuestionsforSDET
4. WhatisMaxSessionPropertiesinSeleniumGrid?
MaxSessionis definedasanumberofbrowsers,independentofthe type &version,can
runinparallelontheremotemachine.
MaxSessionoverridesthe MaxInstancessettingsandhencecanrestrict thenumberof
browserinstancesthatcanrun in parallel.
Foreg.
If maxSession=1 then only a single browser will run in remote machine. If
maxSession=2thenanytwobrowsers canrunatatime
irrespectiveofMaxInstancesthatwedefined.Itcanbeeither2InternetExploreror2FireFoxor1Inte
rnetExplorerand1Firefox.
browserbrowserName=firefox,maxInstances=5,maxSession=2
AdvancedSeleniumInterviewQuestionsforSDET
5. Howcanwehandle Web-basedPop-upsorAlertsinSelenium?
Web-basedalertsorpopupsarehandledbyswitchingtothealertwindowandcalling
SeleniumWebDriverAlertAPImethods.
Below methodsarecalledforvariousactions:
• dismiss():ToclickonCancelbutton.
• accept():ToClickon OKbutton.
• getText():Toget thetextwhichispresentonthe Alert.
• sendKeys():Toenterthetext intothealertbox.
AdvancedSeleniumInterviewQuestionsforSDET
6. WhathappenifyoumixbothThread.SleepandWebDriverWaitsina
SeleniumScript?
Thread.sleep()method isusedtopausetheexecutionofscript forspecifiedtimein
milliseconds
IfWebDriverwaitsareusedalongwith
Thread.sleep()method,thenwebdriverwillholdtheexecutionforspecifiedtime(asmentione
dinThread.sleep())andthenwillfollowotherwait.Ifwemixboththewaits,thentestexecution
timewillincrease.
AdvancedSeleniumInterviewQuestionsforSDET
7. HowcanyouusetheRecoveryScenarioinSeleniumWebDriver?
RecoveryScenariosare usedbyusing“TryCatch”blockwithinSeleniumWebDriverJava
tests.
try{driver.get("https://www.devlabsalliance.com")
;
}
catch{
System.Out.println(e.getMessage());
}
AdvancedSeleniumInterviewQuestionsforSDET
8. WhatisRobotClassinSeleniumand whatareits advantages?
Robot Class is used to control the keyboard or mouse to interact with Operating
Systemwindows like download pop-ups, alerts, print pop-ups, etc or native OS applications likeNotepad,Calculator,
Skype,etc.whiledoingbrowserautomation.
ThevariousadvantagesofRobotClassare:
• ItsimulatesMouseandKeyboardevents.
• Ithelpsinupload/downloadoffileswhileusingSeleniumwebdriver.
• Itgetseasily integratedwithcurrent automationframework(keyword-driven,data-
drivenorhybridframework).
AdvancedSeleniumInterviewQuestionsforSDET
9. WhatarevariousRobotClassinternalmethodsandexplaintheir
usage.
SomeoftheRobotClass Internalmethodsandtheirusageareasfollows:
• keyPress():eg.:robot.keyPress(KeyEvent.VK_Down):Thismethod will press downthe
arrowkeyofkeyboard.
• mouseMove():eg.robot.mouseMove(point.getX(),point.getY()):Thiswillmovethemousep
ointertospecificXandY coordinates.
• mousePress():eg.robot.mousePress(InputEvent.BUTTON_DOWN_MASK):This
methodwill presstherightclickofmouse.
• mouseRelease():eg.robot.mouseRelease(InputEvent.BUTTON_DOWN_MASK):This
methodwill releasethe rightclickofmouse.
• keyRelease():eg.robot.keyRelease(KeyEvent.VK_DOWN):Thismethodwillreleasethedo
wnarrowkeyofkeyboard.
AdvancedSeleniumInterviewQuestionsforSDET
10. HowtoUploadafileinSeleniumWebDriver?
Wecan uploadafile in SeleniumWebDriver usingthe AutoITscript.Followthe
followingstepsforuploadingafilewithAutoITscript:
• DownloadandInstall the“AutoIT”.
• OpenEclipseandwritecodethroughSeleniumWebDriverforclickingonthe“Upload
File”button.
• EnsureFileUpload.exeisgeneratedaftercompilationinthe
locationwhereAutoITisinstalled. This FileUpload.exe already contains the file(say,
devLabsAlliance.docx) to beuploadedandthisispre-configuredthroughAutoITeditor.
• After clickofUpload button,AutoIT scriptneedstobe called
andthencontrolimmediately transferred to AutoIT in order to upload a file and
then control is sentbacktoSelenium.
Syntaxforcalling AutoITscript:
Runtime.getRuntime().exec("D:\\AutoIT\\FileUpload.exe");
AdvancedSeleniumInterviewQuestionsforSDET
11. HowtorunSeleniumtestfromCommandLineinSelenium
WebDriver?
Fordoingthis,weneedtoinstallTestNG,andneedtosetthe class-path.
Followthebelowsteps:
• Createtestng.xmlfileandstorethis xml fileintoprojecthomedirectory.
• EnsurethatyouputalltheSeleniumjarsinseparatefolder andkeepthatfolder into
projecthome directory.
• OpenCommand Promptand typecd\and thenpressEnter.
• Nowcopythepath ofyourprojecthomedirectory in this cd directory path and thenpress
Enter.
• Nowset the classpathforthis andspecifythe binfolder.
ProjectDirectory>setclasspath=ProjectDirectory\bin;andpressenter
• Nowspecifythe folder(say,lib)whereallthe jarsareavailable.
ProjectDirectory>setclasspath=ProjectDirectory\lib\*;andpressenter
• Nowrunxmlfile usingbelowcommand:
Project-directory>javaorg.testng.TestNGtestng.xmlandhitEnter.
AdvancedSeleniumInterviewQuestionsforSDET
12. HowtoconnectadatabaseinSelenium?
Toconnect adatabaseinSelenium,weuseJDBCdriverwhileusingJavaProgramminglanguage.
FollowthebelowstepstoconnectdatabaseinSelenium:
• LoadtherequiredJDBC
driverclass.Class.forName("net.sourceforge.jtds.j
dbc.Driver");
• Establisha connectiontothedatabase:
Connectioncon=DriverManager.getConnection("DataBaseURL","userName","password");
• ConnectionURL:
jdbc:sqlserver://ipAddress:portNumber/dbName
• ExecuteSQLQueries:
StatementsqlStatement=con.createStatement();
StringsqlQuery="SELECT*FROMtable_nameWHEREcondition"
ResultSetresSet=sqlStatement.executeQuery(sqlQuery);
• Fetching
datafromresultSet:while(resSet
.next()){
System.out.println(resSet.getString(required_column_name));}
• Closingthe database connection.
con.close();
AdvancedSeleniumInterviewQuestionsforSDET
13. HowtoScrollWebPageDownOrUpUsingSeleniumWebDriver?
Toscrollthepage UporDown,JavaScriptscrollBy()methodisused.
SyntaxforScrollingWebPagedown:
WebDriverdriver=newChromeDriver();driver.navigate().to("https:
//www.devlabsalliance.com");JavascriptExecutor js = (JavascriptExecutor)
driver;js.executeScript("window.scrollBy(0,250)","");
SyntaxforScrollingWebPageUp:
WebDriverdriver=newChromeDriver();driver.navigate().to("https:
//www.devlabsalliance.com");JavascriptExecutor js = (JavascriptExecutor)
driver;js.executeScript("window.scrollBy(0,-250)","");
AdvancedSeleniumInterviewQuestionsforSDET
14. WhatisDesiredCapabilities?
Desired capabilities are used in to handle SSL certificates in Chrome
browser.Toachievethis,weneedtocreate
aninstanceofDesiredCapabilities:DesiredCapabilitiesdesiredCapability=Desire
dCapabilities.chrome();
AdvancedSeleniumInterviewQuestionsforSDET
15. Howto HighlightElementUsingSeleniumWebDriver?
WecanhighlightthespecifiedelementusingJavaScriptExecuterinterface.
WebDriverdriver=
newChromeDriver();driver.get("https://www.devlabsalliance.co
m");
WebElementele=driver.findElement(By.xpath("//*[@id='devLabs']"));Javasc
riptExecutorjs=(JavascriptExecutor)driver;
//Passingvaluesbasedoncssstyle.Yellowbackgroundcolorwithsolidredcolorborder.js.executeScript("arg
uments[0].setAttribute('style', 'background: yelow; border: 3px solidred;');",ele)
AdvancedSeleniumInterviewQuestionsforSDET
16. HowtolaunchabatchfileinaSeleniumwebdriver?
Beforestartingthe automation,we needtoset upthepre-requisitesinatestsuitetorun a
batchfileoranexecutablefile.
Belowcodecanbeusedforthesame:
ProcessbatchFile=Runtime.getRuntime.exec(“Pathofbatchfile”);
batchFile.waitFor();
AdvancedSeleniumInterviewQuestionsforSDET
17. HowSeleniumWebdrivertestcanberunfromthecommandline?
Below code is used to write Selenium Webdriver test using command
line:java-classpath“.;selenium-server-standalone-2.33.0.jar”ExampleClass
AdvancedSeleniumInterviewQuestionsforSDET
18. WhichSeleniumtechnologyisusefulfordistributeddataprocessing?
SeleniumGridispopularlyused fordistributeddataprocessing.SeleniumGriddistributes
testsonmultiplemachinesinparallel.
Thetestscanbeexecutedinparallelondifferentoperatingsystemsanddifferentweb
browsersatthesametimewithasinglescriptusingSeleniumGrid.
DistributeddataprocessinginSeleniumreducesoveralltimeofexecutionandfeedbackisalso
quickindistributeddataprocess.
AdvancedSeleniumInterviewQuestionsforSDET
19. ExplainwhatthefollowingsnippetofJavacodedoesinbrief:
WebElementexample=
driver.findElement(By.xpath(“//*[contains(text(),‘data’)]”));
Theabovecodeisdefiningavariable‘example’oftype WebElementanditisinitializingit
withareferencetoan elementthatcontains thetext value“data” usingXPathsearch.
AdvancedSeleniumInterviewQuestionsforSDET
20. WhatisStaleElementException?
StaleElementExceptionisanexceptionwhichisthrownwhentheelementthat isinvoked
is nolongerattachedtotheDOM(Document ObjectModel)foranyreason.
Foreg.Iftheelementfoundin aweb pageisreferencedas aWebElementin theWebdriver.
Now if the DOM changes, then WebElement is no longer available,
henceWebElementgoesstale.Thenifwe trytointeractwiththis stale
element,thentheStaleElementExceptionisthrown.
Visitusat:www.devlabsalliance.comEm
ail:[email protected]
t: +919717514555
Comments