<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-2973787519736718861</atom:id><lastBuildDate>Sat, 11 Apr 2026 07:16:38 +0000</lastBuildDate><category>selenium webdriver</category><category>WebDriver</category><category>webdriver tutorials</category><category>Selenium 2</category><category>WebDriver Examples</category><category>selenium ide</category><category>manual testing</category><category>software testing</category><category>selenium tutorial</category><category>Appium</category><category>Appium Tutorials</category><category>mobile automation</category><category>selenium webdriver tutorial</category><category>Appium Android Examples</category><category>selenium</category><category>Selenium 3</category><category>java tutorials for webdriver</category><category>AndroidDriver</category><category>Apache Jmeter</category><category>selenium interview questions and answers</category><category>ISTQB</category><category>tutorial jmeter</category><category>Assertion Commands</category><category>store commands</category><category>WebDriver Datadriven Framework</category><category>Advanced Selenium IDE</category><category>verification commands</category><category>Load Testing</category><category>Load Testing Tool</category><category>using jmeter</category><category>selenium IDE tutorial</category><category>TestNG Tutorials</category><category>Waitfor Commands</category><category>webdriver with testng</category><category>webdriver interview questions</category><category>Bug Tracking Tool</category><category>Test Management Tools</category><category>Test Link</category><category>selenium 4</category><category>Using javascript with selenium IDE</category><category>java tutorials for selenium</category><category>Select commands</category><category>jira</category><category>Selenium IDE tutorials</category><category>project management tool</category><category>Jmeter Logic Controllers</category><category>Jmeter timers</category><category>Junit with webdriver</category><category>Selenium Grid 2</category><category>Element Locators</category><category>JUnit</category><category>KeyBoard Commands</category><category>Mouse Commands</category><category>Selenium IDE advanced</category><category>java Collection interface</category><category>testng.xml</category><category>java Collection framework</category><category>Appium Interview Questions</category><category>Xpath Locator</category><category>appium interview questions and answers</category><category>Jmeter Config Elements</category><category>Webdriver Element Locators</category><category>Xpath Tutorials</category><category>jmeter testing</category><category>performance testing</category><category>AutoIT Tutorials</category><category>Learn Selenium Webdriver Online</category><category>WebDriver Assertions</category><category>explicit wait</category><category>runScript Command</category><category>security testing.</category><category>storeEval command</category><category>Bugzilla</category><category>CSS Locator</category><category>Data Driven Testing in webdriver</category><category>Execute Javascript In Selenium WebDriver</category><category>Extending Selenium IDE</category><category>Firefox Add on</category><category>Jmeter Assertions</category><category>Selenium IDE plugins</category><category>Test Case Management Tool</category><category>jmeter windows</category><category>storeSelectOptions Command</category><category>verifyTextPresent Command</category><category>Appium Tutorial</category><category>Checkbox related commands</category><category>WebDriver Wait For Examples</category><category>addSelection command</category><category>click command</category><category>echo command</category><category>gotoIf Command</category><category>highlight Command</category><category>selectWindow Command</category><category>selenium with python</category><category>while Command</category><category>Handling Multiple Windows In Selenium IDE</category><category>Parameterization in selenium ide</category><category>Webdriver Report Using JUnit</category><category>difference between &quot;assert&quot; and &quot;verify&quot; in selenium</category><category>endWhile Command</category><category>getEval Command</category><category>gotoLabel Command</category><category>pause command</category><category>refreshAndWait Command</category><category>selectPopUp Command</category><category>store command</category><category>type command</category><category>Adding Listeners in Test Plan</category><category>Aggregate Report Listener</category><category>Data driven testing</category><category>Deselecting Dropdown Value</category><category>Matching Text Patterns</category><category>Parameterization in webdriver</category><category>Performance Testing Tool</category><category>Selecting Dropdown Value</category><category>SelectorsHub for chrome</category><category>Selenium IDE add on</category><category>What is selenium webdriver</category><category>assertText command</category><category>assertValue Command</category><category>captureEntirePageScreenshot Command</category><category>close Command</category><category>deselectPopUp Command</category><category>dragAndDrop command</category><category>dragAndDropToObject command</category><category>driver.get</category><category>driver.getCurrentUrl</category><category>how can i download java</category><category>how do i download java</category><category>keyDown command</category><category>keypress Command</category><category>open command</category><category>removeSelection command</category><category>selectorshub tutorial</category><category>selenium commands list</category><category>selenium find element by name</category><category>selenium methods</category><category>sendKeys Command</category><category>setSpeed command</category><category>storeAttribute command</category><category>storeElementHeight command</category><category>storeElementWidth command</category><category>storeLocation Command</category><category>storeTable Command</category><category>storeText command</category><category>storeTitle Command</category><category>storedVars</category><category>verifyTitle Command</category><category>waitForElementPresent command</category><category>waitForPageToLoad command</category><category>xpath in selenium</category><category>&quot;verifyNotAlert&quot; Command</category><category>ANDROID_HOME</category><category>Apache JMeter Installation Steps</category><category>Apache Jmeter - First Test plan recording steps</category><category>Apache Jmeter - First Test plan running steps</category><category>Automation Testing Tools</category><category>CSS selector in selenium</category><category>Download and Install WebDriver</category><category>Download and install Eclipse</category><category>Download and install Java</category><category>Extracting links from page</category><category>File Logging Plugin</category><category>Generate And Insert Log</category><category>Generating Mouse Hover Event</category><category>Generating random number</category><category>Globbing Patterns</category><category>Handling Multiple Windows</category><category>Highlight Elements Plugin</category><category>Integrated testing</category><category>Integration testing</category><category>Interleave Controller</category><category>Listeners</category><category>Locate element</category><category>Locator Builders</category><category>Loop Controller</category><category>Number of Threads VS Ramp-Up Period</category><category>Once Only Controller</category><category>Open source Tools</category><category>Random Controller</category><category>Regular Expression Patterns</category><category>Rollup Command</category><category>Run First Webdriver Script</category><category>Screenshot on fail plugin</category><category>Selenium IDE Command Prompt</category><category>Selenium IDE General Settings</category><category>Selenium IDE Interview Questions</category><category>Selenium IDE Questions and answers</category><category>Selenium IDE Test Results plugin</category><category>Selenium IDE quiz</category><category>Selenium IDE test paper</category><category>Set Locator Builders Preference</category><category>Stored Variables Viewer plugin</category><category>String concatenation in selenium ide</category><category>System.setProperty</category><category>Thread Group Properties</category><category>Transaction Controller</category><category>Verify Element Enabled</category><category>View Results Tree Listener</category><category>acceptance testing</category><category>addSelectionAndWait command</category><category>altKeyDown command</category><category>altKeyUp command</category><category>answerOnNextPrompt command</category><category>ant</category><category>assertAlert command</category><category>assertAlertNotPresent Command</category><category>assertAlertPresent Command</category><category>assertAttribute Command</category><category>assertConfirmation Command</category><category>assertConfirmationNotPresent Command</category><category>assertConfirmationPresent Command</category><category>assertEditable Command</category><category>assertElementHeight command</category><category>assertElementNotPresent command</category><category>assertElementPresent command</category><category>assertElementWidth command</category><category>assertEquals</category><category>assertEval Command</category><category>assertLocation command</category><category>assertNotAlert Command</category><category>assertNotChecked Command</category><category>assertNotEditable Command</category><category>assertNotElementHeight Command</category><category>assertNotElementWidth Command</category><category>assertNotLocation command</category><category>assertNotSelectOptions Command</category><category>assertNotSelectedIndex Command</category><category>assertNotSelectedIndexes Command</category><category>assertNotSelectedLabel Command</category><category>assertNotSelectedLabels Command</category><category>assertNotSomethingSelected Command</category><category>assertNotTable Command</category><category>assertNotText Command</category><category>assertNotTitle Command</category><category>assertNotValue Command</category><category>assertNotVisible Command</category><category>assertOrdered Command</category><category>assertPrompt command</category><category>assertSelectOptions Command</category><category>assertSelectedId Command</category><category>assertSelectedIds Command</category><category>assertSelectedIndex Command</category><category>assertSelectedIndexes Command</category><category>assertSelectedLabel Command</category><category>assertSelectedLabels</category><category>assertSelectedValue Command</category><category>assertSelectedValues</category><category>assertSomethingSelected Command</category><category>assertTable Command</category><category>assertTextNotPresent command</category><category>assertTextPresent command</category><category>assertTitle Command</category><category>assertVisible Command</category><category>assertchecked Command</category><category>assignId Command</category><category>break Command</category><category>bug</category><category>check command</category><category>checkAndWait command</category><category>chooseCancelOnNextConfirmation command</category><category>chooseOkOnNextConfirmation command</category><category>clickAndWait command</category><category>clickAt command</category><category>clickAtAndWait command</category><category>disableJavascript Command</category><category>driver.findElement</category><category>driver.getTitle</category><category>enableJavascript Command</category><category>find by linktext</category><category>findElements</category><category>fireEvent command</category><category>focus Command</category><category>goBack Command</category><category>implicit wait in webdriver</category><category>iselementpresent</category><category>iselementpresent in selenium webdriver</category><category>iselementpresent method in selenium</category><category>java Map interface</category><category>java jmeter</category><category>javascript</category><category>keyUp Command</category><category>label Command</category><category>manual testing interview questions</category><category>mouseDown command</category><category>mouseMoveAt command</category><category>mouseOut Command</category><category>mouseOutAndWait Command</category><category>mouseOver Command</category><category>mouseOverAndWait Command</category><category>mouseUp command</category><category>openMultipleWindow Command</category><category>openWindow command</category><category>push Command</category><category>qa training</category><category>refresh command</category><category>regression testing tool</category><category>relative=up</category><category>removeSelectionAndWait command</category><category>select Command</category><category>selectAndWait command</category><category>selectPopUpAndWait Command</category><category>selectframe command</category><category>selenium find element by id</category><category>selenium interview questions</category><category>selenium online training</category><category>selenium training online</category><category>setTimeout command</category><category>shiftKeyDown Command</category><category>shiftKeyUp Command</category><category>soap ui</category><category>soapui tutorial</category><category>soupui</category><category>store</category><category>storeAlert Command</category><category>storeAllButtons Command</category><category>storeAllFields Command</category><category>storeAllLinks Command</category><category>storeChecked Command</category><category>storeConfirmation Command</category><category>storeCssCount Command</category><category>storeEditable Command</category><category>storeElementIndex Command</category><category>storeElementPositionLeft command</category><category>storeElementPositionTop command</category><category>storePrompt Command</category><category>storeSelectedIndex Command</category><category>storeSelectedIndexes Command</category><category>storeSelectedLabel Command</category><category>storeSelectedLabels Command</category><category>storeSelectedValue command</category><category>storeSelectedValues command</category><category>storeTextPresent command</category><category>storeValue Command</category><category>storeVisible Command</category><category>storeXpathCount</category><category>system testing</category><category>tag name</category><category>testcase</category><category>typeAndWait command</category><category>types of testing</category><category>uncheck command</category><category>uncheckAndWait command</category><category>unit testing</category><category>verify</category><category>verifyAlert command</category><category>verifyAlertNotPresent command</category><category>verifyAlertPresent command</category><category>verifyAttribute Command</category><category>verifyChecked Command</category><category>verifyConfirmation Command</category><category>verifyCssCount Command</category><category>verifyEditable Command</category><category>verifyElementIndex Command</category><category>verifyElementNotPresent Command</category><category>verifyEval Command</category><category>verifyLocation command</category><category>verifyNotEditable Command</category><category>verifyNotLocation command</category><category>verifyNotSelectedId Command</category><category>verifyNotSelectedIndex Command</category><category>verifyNotSelectedIndexes Command</category><category>verifyNotSomethingSelected command</category><category>verifyNotTable command</category><category>verifyNotText Command</category><category>verifyNotTitle Command</category><category>verifyNotVisible Command</category><category>verifyOrdered Command</category><category>verifyPrompt Command</category><category>verifySelectOptions Command</category><category>verifySelectedId Command</category><category>verifySelectedIndex Command</category><category>verifySelectedLabel Command</category><category>verifySelectedValue Command</category><category>verifySelectedValues Command</category><category>verifySomethingSelected command</category><category>verifyTable command</category><category>verifyText command</category><category>verifyTextNotPresent Command</category><category>verifyValue Command</category><category>verifyVisible Command</category><category>verifyelementpresent command</category><category>wait for alert</category><category>wait for invisibility of Element</category><category>wait for text</category><category>wait for title</category><category>wait for visibility of Element</category><category>waitForAlert</category><category>waitForAlertPresent</category><category>waitForAllButtons command</category><category>waitForAllFields command</category><category>waitForChecked command</category><category>waitForCondition Command</category><category>waitForEditable Command</category><category>waitForElementNotPresent Command</category><category>waitForNotChecked command</category><category>waitForNotEditable Command</category><category>waitForNotText Command</category><category>waitForNotTitle Command</category><category>waitForNotVisible Command</category><category>waitForPopUp Command</category><category>waitForTable Command</category><category>waitForText Command</category><category>waitForTextNotPresent Command</category><category>waitForTextPresent Command</category><category>waitForTitle Command</category><category>waitForVisible Command</category><category>webdriver tutorial</category><title>Software testing tutorials and automation</title><description>A blog on Selenium tutorial, Selenium webdriver tutorial, Selenium IDE tutorial, Appium Tutorial, Selenium Grid Tutorial, Jmeter Tutorial.</description><link>http://software-testing-tutorials-automation.blogspot.com/</link><managingEditor>noreply@blogger.com (Unknown)</managingEditor><generator>Blogger</generator><openSearch:totalResults>753</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-5737771388379347765</guid><pubDate>Tue, 18 Mar 2025 12:58:00 +0000</pubDate><atom:updated>2025-03-18T06:13:17.543-07:00</atom:updated><title>5 Options to Combine Two Columns in Excel (With space, comma, and dash)</title><description>&lt;p&gt;Ever had two columns of data in Excel that you want to merge&amp;nbsp;magically into one column?&lt;/p&gt;&lt;p&gt;Suppose, You have a first name in one column, and the last names are in another, and you want to merge them into one clean list—without spending hours copy-pasting.&lt;/p&gt;&lt;p&gt;It is a time-consuming and tedious task to copy and paste&amp;nbsp;each one manually.&lt;/p&gt;&lt;p&gt;Here is some good news: There’s a super simple way to combine columns in Excel… and I will show you exactly how.&lt;/p&gt;&lt;p&gt;No stress, no fuss. This quick guide walks you through five simple ways to get it done.&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;When Would You Need This?&lt;/h2&gt;&lt;div&gt;&lt;div&gt;Before we dive in, here are a few common reasons you might want to combine columns:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Creating full names from first and last names&lt;/li&gt;&lt;li&gt;Joining product names with categories or codes&lt;/li&gt;&lt;li&gt;Merging address fields into a single-line&lt;/li&gt;&lt;li&gt;Cleaning up messy data so it’s easier to read or export&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;Sound familiar? Cool. Let’s get into it.&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;The Fastest Way to Combine Two Columns with a Space in Excel&lt;/h2&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Imagine this setup:&lt;/p&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Column C&lt;/b&gt; has the first names.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Column D&lt;/b&gt; has the last names. Now you want a &lt;b&gt;full name&lt;/b&gt; in &lt;b&gt;Column E&lt;/b&gt;, with a space in between.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Option 1: Use a Simple Formula (The &amp;amp; Trick) to Combine Two Columns&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Steps to join columns using &amp;amp; (&lt;a href=&quot;https://en.wikipedia.org/wiki/Ampersand&quot; target=&quot;_blank&quot;&gt;Ampersand&lt;/a&gt;)&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;To combine two columns in Excel:&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Click/Select &lt;b&gt;E2 cell&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Type in this formula:&amp;nbsp;&lt;b&gt;= C2 &amp;amp; &quot; &quot; &amp;amp; D2&lt;/b&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZe30yV6c-3QdZnli5pyw5WxDTAfBy4YY5PdxjQQWPh4djB-ep7h2ea1ZWgswDKUsWnISzm64QUtmF32udub3SlaIcbtQpZMU0LT6gF68ev2n-sMXwGLsfg491HzWgECQcZg19fELim1_lvYEqUEZ50v7EH5sZyXyeMUZqAEPxQFYYHsPQVGqVICKzP1cV/s462/Combine%20Two%20Columns%20in%20Excel%20with%20space.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;combining two columns with space in excel&quot; border=&quot;0&quot; data-original-height=&quot;246&quot; data-original-width=&quot;462&quot; height=&quot;170&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZe30yV6c-3QdZnli5pyw5WxDTAfBy4YY5PdxjQQWPh4djB-ep7h2ea1ZWgswDKUsWnISzm64QUtmF32udub3SlaIcbtQpZMU0LT6gF68ev2n-sMXwGLsfg491HzWgECQcZg19fELim1_lvYEqUEZ50v7EH5sZyXyeMUZqAEPxQFYYHsPQVGqVICKzP1cV/w320-h170/Combine%20Two%20Columns%20in%20Excel%20with%20space.png&quot; title=&quot;Formula to combine two columns with space in Microsoft Excel&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Hit the Enter button&amp;nbsp;&lt;/b&gt;and boom—Excel combines the two!&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;What’s Happening Here?&lt;/b&gt;&lt;/h4&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;C2 is your first column i.e.&amp;nbsp;&quot;Elizabeth&quot;&lt;/li&gt;&lt;li&gt;&quot; &quot; adds a space.&lt;/li&gt;&lt;li&gt;D2 is your second column i.e.&amp;nbsp;&quot;Smith&quot;&lt;/li&gt;&lt;li&gt;When you press the Enter button,&amp;nbsp;you’ll get Elizabeth Smith in E2.&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Easy, right?&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Now,&amp;nbsp;Grab that little square &lt;b&gt;(+ sign)&lt;/b&gt; in the bottom-right corner of the E2 cell (the fill handle) and drag it down to copy the formula to the rest of your rows.&lt;/p&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOTUSbMd-kCICNwOFaFw-WqDZnlKqrgqp8vhKjndXvWNpDh0dL_-qjbpNL4lZ_43dfR7YehW5uzAYUD2rkZVTUoDfDWlXQbfMIoXqZ0OdRgZpwlgB-vF0KlaxOyoKc9SvaHNudJBs42wMbbFLbUssah-P4F__HO-bK-Dl4H_HWqf7A7pLmyYY2jucZVRHF/s812/drag%20Combine%20culumn%20formula%20in%20remaining%20rows%20in%20Excel.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;244&quot; data-original-width=&quot;812&quot; height=&quot;120&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOTUSbMd-kCICNwOFaFw-WqDZnlKqrgqp8vhKjndXvWNpDh0dL_-qjbpNL4lZ_43dfR7YehW5uzAYUD2rkZVTUoDfDWlXQbfMIoXqZ0OdRgZpwlgB-vF0KlaxOyoKc9SvaHNudJBs42wMbbFLbUssah-P4F__HO-bK-Dl4H_HWqf7A7pLmyYY2jucZVRHF/w400-h120/drag%20Combine%20culumn%20formula%20in%20remaining%20rows%20in%20Excel.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;We applied the same formula to the remaining rows.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Merge using comma(,) and Dash(-)&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can use:&lt;/p&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;= C2 &amp;amp; &lt;b&gt;&quot;,&quot;&lt;/b&gt; &amp;amp; D2 formula to combine using the comma.&lt;/li&gt;&lt;li&gt;= C2 &amp;amp; &quot;-&quot; &amp;amp; D2&amp;nbsp;formula to merge using the dash in between.&lt;/li&gt;&lt;/ul&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Use of TEXT Function (For Formatting and Combining Numbers/Dates)&lt;/h4&gt;&lt;p&gt;If you’re combining numbers or dates and want them formatted nicely, use TEXT() inside your formula.&lt;/p&gt;&lt;p&gt;Example:&amp;nbsp;&lt;b&gt;=B2 &amp;amp; &quot;. &quot; &amp;amp; C2 &amp;amp; &quot; &quot; &amp;amp; D2 &amp;amp; &quot; - &quot; &amp;amp;&amp;nbsp; TEXT(E2, &quot;mm/dd/yyyy&quot;)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfiJDevVkUAliEc3Mz7EHmc0BvPjWReJ-QgiNRAYqaEna1LHmIWL1kltTScaVada3JdNTTy40v0BuDoTorK5Aj_5FCVrV6RCt_XSQsStysQ4bLG8RMOQRrLBCr39V-jp6XLGpooOrEQrWeI1wOdrq69QOmufeIpP2cCDRirrzlLbwYbjzTlkmEU5vs6Gxi/s948/merge%20dates%20and%20numbers%20using%20text()%20function.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;combine date and number columns&quot; border=&quot;0&quot; data-original-height=&quot;277&quot; data-original-width=&quot;948&quot; height=&quot;188&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfiJDevVkUAliEc3Mz7EHmc0BvPjWReJ-QgiNRAYqaEna1LHmIWL1kltTScaVada3JdNTTy40v0BuDoTorK5Aj_5FCVrV6RCt_XSQsStysQ4bLG8RMOQRrLBCr39V-jp6XLGpooOrEQrWeI1wOdrq69QOmufeIpP2cCDRirrzlLbwYbjzTlkmEU5vs6Gxi/w640-h188/merge%20dates%20and%20numbers%20using%20text()%20function.png&quot; title=&quot;using text() function to merge dats and numbers columns in excel&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here you can see that Colum B has a number and E has a date. We applied the TEXT() function to merge all four column values in the F column.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Tips&lt;/b&gt;: If you want to combine more than two columns i.e. B2, C2, and D2, You can use the formula &lt;b&gt;= B2 &amp;amp; &quot; &quot; &amp;amp; C2 &amp;amp; &quot; &quot; &amp;amp; D2&lt;/b&gt;&lt;/p&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Other Ways to Combine Two Columns (If You’re Feeling Fancy)&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here are other options which you can use to combine two or more columns of data.&lt;/p&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Option 2: Use TEXTJOIN()&lt;/h3&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;This function is perfect for working with more than two columns or for ignoring blank cells.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Suppose you have a scenario in which a First name is in column C, a Last name is in Column D, an Address is in column E and a few cells are empty. You want to combine them in column F.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Steps to join cells using&amp;nbsp;TEXTJOIN function.&lt;/p&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Select cell &lt;b&gt;F2&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Type in formula&amp;nbsp;&lt;b&gt;=TEXTJOIN(&quot;, &quot;, &quot;&quot;, C2, D2, E2)&lt;/b&gt;&lt;/li&gt;&lt;li&gt;Hit &lt;b&gt;Enter&lt;/b&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxMlIP1akv0oDvoWymhEQ05Mc8mkUcTkMGjybTR5eW6l6XTwCuQR1rvy34WQ9ip4DrO3RpDrIOlpNlLS0d2vclFdRqwVUveGjB8cCJ7Bwiwogm64-UkXsAM8xRagb1TpkhsAra_JPjKNe_kb4ccsgwCVJX9yYDONtlX6NLKvC0xAO0vKmjht6kLNUVAqR2/s1011/merge%20multiple%20columns%20using%20TEXTJOIN%20function.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Excel Merge cells using the TEXTJOIN&quot; border=&quot;0&quot; data-original-height=&quot;218&quot; data-original-width=&quot;1011&quot; height=&quot;138&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxMlIP1akv0oDvoWymhEQ05Mc8mkUcTkMGjybTR5eW6l6XTwCuQR1rvy34WQ9ip4DrO3RpDrIOlpNlLS0d2vclFdRqwVUveGjB8cCJ7Bwiwogm64-UkXsAM8xRagb1TpkhsAra_JPjKNe_kb4ccsgwCVJX9yYDONtlX6NLKvC0xAO0vKmjht6kLNUVAqR2/w640-h138/merge%20multiple%20columns%20using%20TEXTJOIN%20function.png&quot; title=&quot;Merging multiple (i.e. more than two columns) using TEXTJOIN function in MS excel&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;What’s Happening Here?&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;div&gt;&lt;ul&gt;&lt;/ul&gt;&lt;/div&gt;&lt;li&gt;The &quot; &quot; part is your separator (in this case, a space). You can use comma or dash as a separator if you need.&lt;/li&gt;&lt;li&gt;TRUE skips any blanks.&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;In the above image, you can see that we have used the TEXTJOIN function to merge data from C, D, and E columns into F.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Quick Tip&lt;/b&gt;: If you type =TEXTJOIN in a cell and it shows a #NAME? error, your Excel (Excel 2016 or earlier versions) version probably doesn’t support it. This function was&amp;nbsp;introduced in Excel 2019 and is available in&amp;nbsp;Excel 365 (Microsoft 365),&amp;nbsp;Excel 2019 for Windows and Mac, and&amp;nbsp;&lt;a href=&quot;https://www.microsoft.com/en-in/microsoft-365/excel&quot; target=&quot;_blank&quot;&gt;Excel Online&lt;/a&gt; (browser version).&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Option 3: Use CONCAT() (For Newer Versions of Excel)&lt;/h3&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If you’ve got Excel 2019 or newer, you can try the CONCAT() function. This is basically an upgrade from CONCATENATE().&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;We will use the same example as described in option 2 to merge three columns.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;A step-by-step guide to joining cells using the TEXTJOIN function.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Click on cell &lt;b&gt;F2&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Write formula&amp;nbsp;&lt;b&gt;=CONCAT(C2, &quot; &quot;, D2, &quot; &quot;, E2)&lt;/b&gt;&lt;/li&gt;&lt;li&gt;Press the &lt;b&gt;Enter key&lt;/b&gt; from the keyboard.&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOYQqCQbRliSbWCas-q4wMH1C4Szg8oAEcoEhO_9-sHkO2HFg74_fcn5VDxV6GpUzDoCD58XpbaVsy3_QkvC88WI26JpPB40pjzukoNEoxNuvTl2IdMylxzd8LQHpiGflFTRIJehZM8YfYGkgorzjuY1-FHO2R6Vl9Hr29PiL84fs8jxGvxYLXcF4OtVoV/s922/combine%20cells%20using%20concat%20function%20in%20excel.PNG&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Use of CONCAT() function in excel&quot; border=&quot;0&quot; data-original-height=&quot;200&quot; data-original-width=&quot;922&quot; height=&quot;138&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOYQqCQbRliSbWCas-q4wMH1C4Szg8oAEcoEhO_9-sHkO2HFg74_fcn5VDxV6GpUzDoCD58XpbaVsy3_QkvC88WI26JpPB40pjzukoNEoxNuvTl2IdMylxzd8LQHpiGflFTRIJehZM8YfYGkgorzjuY1-FHO2R6Vl9Hr29PiL84fs8jxGvxYLXcF4OtVoV/w640-h138/combine%20cells%20using%20concat%20function%20in%20excel.PNG&quot; title=&quot;Combine cells using CONCAT() function in excel&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Why&amp;nbsp;CONCAT() instead of&amp;nbsp;CONCATENATE()&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Starting with &lt;b&gt;Excel 2016&lt;/b&gt;, Microsoft introduced the CONCAT() function as a &lt;b&gt;more powerful and flexible&lt;/b&gt; replacement for CONCATENATE().&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Key points&lt;/b&gt;:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;CONCATENATE() is &lt;b&gt;still available&lt;/b&gt; in Excel 2016 and later versions &lt;b&gt;for backward compatibility&lt;/b&gt;, but it&#39;s considered &lt;b&gt;deprecated&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Microsoft recommends using CONCAT() or TEXTJOIN() (introduced in Excel 2016) going forward.&lt;/li&gt;&lt;/ul&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Option 4:&amp;nbsp;Flash Fill (The Lazy Person’s Hack!)&lt;/h3&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Flash Fill is Excel’s auto-magic tool that detects patterns and fills in the rest for you. No formula is required!&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;How to use it:&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;In E2, manually type&amp;nbsp;Elizabeth Smith as per our example.&lt;/li&gt;&lt;li&gt;Press the Enter button. Cursor will move on E3&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDDRbuV43XpvD2MmdFLwwV9yIVPmrO3AU5grjvwTOYb__Pvfcy_WfQKsmcrA4mG-lMLIAj2tXo7ZtBr9HqHGe4ns3ZJ9iQHb31oA2nUAaYorMoNTn01muuYZ60rIA_BnQuhqEnwt0osv1iqLXNmNhS4gGdGV1ckOzR43ka7QE4TDo7SluOinXXPqh3HQ3M/s579/combine%20using%20Flash%20Fill.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Flash Fill function&quot; border=&quot;0&quot; data-original-height=&quot;247&quot; data-original-width=&quot;579&quot; height=&quot;171&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDDRbuV43XpvD2MmdFLwwV9yIVPmrO3AU5grjvwTOYb__Pvfcy_WfQKsmcrA4mG-lMLIAj2tXo7ZtBr9HqHGe4ns3ZJ9iQHb31oA2nUAaYorMoNTn01muuYZ60rIA_BnQuhqEnwt0osv1iqLXNmNhS4gGdGV1ckOzR43ka7QE4TDo7SluOinXXPqh3HQ3M/w400-h171/combine%20using%20Flash%20Fill.png&quot; title=&quot;manually type text to apply Flash Fill function&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Start typing the next combined value in E3, like: Maria.&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjb2NQl37RvZpBTokd6VoYlVsG2NQmrjQAXC-sXypRRQ4qcTXNz0FtYCYzmGkRlTXq4QL4vctvSuRwbmq2HKuiBOP9J3pFgND7TFn-S88_ZuLY5-8eNyhcFLKG9h7bONAjw3EnKOB0JRLqNcjTwpqvwNw3LNyU-nEpNVwfHBvxtEcw6Xq2onPLhCSwEqP_X/s580/apply%20Flash%20Fill%20when%20you%20type%20first%20character%20in%20excel.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Apply flash fill in excel&quot; border=&quot;0&quot; data-original-height=&quot;244&quot; data-original-width=&quot;580&quot; height=&quot;169&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjb2NQl37RvZpBTokd6VoYlVsG2NQmrjQAXC-sXypRRQ4qcTXNz0FtYCYzmGkRlTXq4QL4vctvSuRwbmq2HKuiBOP9J3pFgND7TFn-S88_ZuLY5-8eNyhcFLKG9h7bONAjw3EnKOB0JRLqNcjTwpqvwNw3LNyU-nEpNVwfHBvxtEcw6Xq2onPLhCSwEqP_X/w400-h169/apply%20Flash%20Fill%20when%20you%20type%20first%20character%20in%20excel.png&quot; title=&quot;applying flash fill by typing text in next cell and hit enter button&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Excel will recognize the pattern and show flash-fill suggestions.&lt;/li&gt;&lt;li&gt;Press the Enter button. Boom! The remaining cells will be filled automatically with the same pattern.&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrOkAsmh3vOs2ef5ckP44a8I2LeHVi06OZzpp-KnlMqsKf_VVE4v-HnB-iHO-MATSzVtFVgmdyiiNjU7cHhPWCEtnGg-yoAU9-X-olMKeDJH7NGpnXTYdCuPqL3uU2j2UQ-1BHieeBBYET5I0R2WUmtFf79zB1uIBzqUiHlyQrcAAbtuVjnzzuFYUMXjlI/s736/flsh%20fill%20data%20in%20excel.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Flash filled data&quot; border=&quot;0&quot; data-original-height=&quot;245&quot; data-original-width=&quot;736&quot; height=&quot;134&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrOkAsmh3vOs2ef5ckP44a8I2LeHVi06OZzpp-KnlMqsKf_VVE4v-HnB-iHO-MATSzVtFVgmdyiiNjU7cHhPWCEtnGg-yoAU9-X-olMKeDJH7NGpnXTYdCuPqL3uU2j2UQ-1BHieeBBYET5I0R2WUmtFf79zB1uIBzqUiHlyQrcAAbtuVjnzzuFYUMXjlI/w400-h134/flsh%20fill%20data%20in%20excel.png&quot; title=&quot;Filled data automatically in remaining cells using flash fill in excel.&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;This is the perfect option for quick-and-dirty tasks, no formulas left behind!&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Option 5:&amp;nbsp;Combine Two Columns Using VBA Macro&lt;/h3&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Scenario&lt;/b&gt;:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You have First Names in Column C and Last Names in Column D, and you want to combine them into Column E, separated by a space.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Steps&lt;/b&gt;:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Step 1: Open Your Excel Workbook&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Make sure your workbook has the data in the C and D columns&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5AMq8JnA7e8kadJ5Yzob1WnRP8JLNka0VTZXAj_h5LZOmFuwqpv3NvaTR9yFD_VExThXyFzkodgpezEsNAA_yhbva5-4Em7to0iNo3c33HHie_qJngpbzwLfWyMrOKs6K4HyG-pbTg-a_XNYE8-DaIyGQGUCoErWItBxIibNrj7s4Lxu7pe9D5GXWNYY-/s408/data%20to%20run%20vba%20macro%20to%20combine%20columns.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;data to run vba macro&quot; border=&quot;0&quot; data-original-height=&quot;256&quot; data-original-width=&quot;408&quot; height=&quot;251&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5AMq8JnA7e8kadJ5Yzob1WnRP8JLNka0VTZXAj_h5LZOmFuwqpv3NvaTR9yFD_VExThXyFzkodgpezEsNAA_yhbva5-4Em7to0iNo3c33HHie_qJngpbzwLfWyMrOKs6K4HyG-pbTg-a_XNYE8-DaIyGQGUCoErWItBxIibNrj7s4Lxu7pe9D5GXWNYY-/w400-h251/data%20to%20run%20vba%20macro%20to%20combine%20columns.png&quot; title=&quot;Data for run macro and combine cells data&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;b&gt;Step 2: Access the VBA Editor&lt;/b&gt;&lt;p&gt;&lt;/p&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Press &lt;b&gt;Alt + F11&lt;/b&gt; on your keyboard.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;This opens the VBA Editor window.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;In the editor, click &lt;b&gt;Insert &amp;gt; Module&lt;/b&gt;.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;A new blank code window will appear where you can write your macro.&lt;/li&gt;&lt;/ul&gt;&lt;/ol&gt;&lt;p style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgq2PQoPBbGwvf4g7BF8OCYkKJuy-c2eZrp5HU-ulE93f7MP0zW-GwGdnUsjcclXYhgDTEIH_pPxk86LV6m1dfKm0V5GQHaRCgjIFip25k9fmpkDNZbkZ4X0bPnmP_5RKhxVUgjDl7D0y5Dfu9FJ9U1UgvI7gBFVrhojNpbpScDhKK2ahK6MuQ5ZqoyF5L/s1339/open%20macro%20interface%20to%20write%20code%20to%20merge%20data.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Create macro&quot; border=&quot;0&quot; data-original-height=&quot;651&quot; data-original-width=&quot;1339&quot; height=&quot;195&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgq2PQoPBbGwvf4g7BF8OCYkKJuy-c2eZrp5HU-ulE93f7MP0zW-GwGdnUsjcclXYhgDTEIH_pPxk86LV6m1dfKm0V5GQHaRCgjIFip25k9fmpkDNZbkZ4X0bPnmP_5RKhxVUgjDl7D0y5Dfu9FJ9U1UgvI7gBFVrhojNpbpScDhKK2ahK6MuQ5ZqoyF5L/w400-h195/open%20macro%20interface%20to%20write%20code%20to%20merge%20data.png&quot; title=&quot;create macro to combine data&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;b&gt;Step 3: Paste the VBA Code&lt;/b&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Here’s a simple macro to combine columns C and D into column E:&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;Sub CombineColumns()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim i As Long

    &#39;Set your worksheet (ActiveSheet means the sheet you&#39;re currently on)
    Set ws = ActiveSheet

    &#39;Find the last row with data in column C
    lastRow = ws.Cells(ws.Rows.Count, &quot;C&quot;).End(xlUp).Row

    &#39;Loop through each row to combine data
    For i = 2 To lastRow
        ws.Range(&quot;E&quot; &amp;amp; i).Value = ws.Range(&quot;C&quot; &amp;amp; i).Value &amp;amp; &quot; &quot; &amp;amp; ws.Range(&quot;D&quot; &amp;amp; i).Value
    Next i

    MsgBox &quot;Columns Combined Successfully!&quot;, vbInformation
End Sub&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;Step 4: Close the VBA Editor&lt;/b&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Click the &lt;b&gt;X&lt;/b&gt; to close the editor.&lt;/li&gt;&lt;li&gt;Go back to your Excel sheet.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Step 5: Run the Macro&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Press &lt;b&gt;Alt + F8&lt;/b&gt;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;This opens the &quot;Macro&quot; dialog box.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Select CombineColumns from the list.&lt;/li&gt;&lt;li&gt;Click &lt;b&gt;Run&lt;/b&gt;.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinmLip4gpUMEoWDYXwUOaPAsEkaSAHnCzTpGTQakyXbQmHspTInzAs4UrjXSmf1alG_hPYTVs51xGzN9TBp9bT1ucKnSxDxTp4B-IBWz3F09sq_alvqDp9P8NCLzjw_GKafHsu7d7N15QyqpGC3NB96_npDRdLKQ7zaxK8XbAC4aHLCa4j5_5FARfJky7M/s759/run%20macro%20to%20combine%20columns%20data.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Run macro&quot; border=&quot;0&quot; data-original-height=&quot;481&quot; data-original-width=&quot;759&quot; height=&quot;254&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinmLip4gpUMEoWDYXwUOaPAsEkaSAHnCzTpGTQakyXbQmHspTInzAs4UrjXSmf1alG_hPYTVs51xGzN9TBp9bT1ucKnSxDxTp4B-IBWz3F09sq_alvqDp9P8NCLzjw_GKafHsu7d7N15QyqpGC3NB96_npDRdLKQ7zaxK8XbAC4aHLCa4j5_5FARfJky7M/w400-h254/run%20macro%20to%20combine%20columns%20data.png&quot; title=&quot;Run macro to combine columns C and D data&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;b&gt;What Happens?&lt;/b&gt;&lt;br /&gt;&lt;p&gt;The macro loops through each row of your data (starting from row 2), combines the First Name and Last Name from columns C and D, and places the full name in column E.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;C2 = Elizabeth&lt;/li&gt;&lt;li&gt;D2 = Smith&lt;/li&gt;&lt;li&gt;E2 becomes Elizabeth Smith&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Breakdown of the VBA Code&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Dim ws As Worksheet: Declares a worksheet variable.&lt;/li&gt;&lt;li&gt;Set ws = ActiveSheet:&amp;nbsp;Sets the active sheet as your working sheet.&lt;/li&gt;&lt;li&gt;lastRow = ws.Cells(...).End(xlUp)...:&amp;nbsp;Finds the last row in column C with data.&lt;/li&gt;&lt;li&gt;For i = 2 To lastRow:&amp;nbsp;Loops from row 2 to the last row.&lt;/li&gt;&lt;li&gt;ws.Range(&quot;E&quot; &amp;amp; i).Value = ...:&amp;nbsp;Combines the values and writes to column E.&lt;/li&gt;&lt;li&gt;MsgBox:&amp;nbsp;Pops up a message when it’s done.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Bonus: Add a Button to Run the Macro (Optional, But Fun!)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Want to click a button instead of pressing Alt + F8 every time?&lt;/p&gt;&lt;p&gt;&lt;b&gt;Here’s how:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;box-sizing: border-box; margin: 0px; padding: 0px;&quot;&gt;Go to the&amp;nbsp;&lt;strong&gt;Developer&amp;nbsp;&lt;/strong&gt;tab. (If you don’t see it, go to File &amp;gt; Options &amp;gt; Customize Ribbon &amp;gt; Check Developer and click OK.)&lt;/span&gt;&lt;/li&gt;&lt;li&gt;Click &lt;b&gt;Insert &amp;gt; Button&lt;/b&gt; (Form Control).&lt;/li&gt;&lt;li&gt;Draw your button anywhere on your sheet.&lt;/li&gt;&lt;li&gt;When prompted, assign your macro (CombineColumns) to it.&lt;/li&gt;&lt;li&gt;Right-click the button to &lt;b&gt;edit the text&lt;/b&gt; (call it &quot;Combine Names&quot; or whatever you like).&lt;/li&gt;&lt;/ol&gt;&lt;p style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8PLX7Ta32DW6Rabnz-UZ-EvfFOx_NPJwwPREypKfPhxa0BqCnqdzHPVidZucPqaMhvN9SogMchKIzJ1_MHL5ZKNlcMKAUnw2f2TtPqoEuT4I-2UierI3zOUVbQwxojgrkOKq4KyRRv8GncvtfTQY4rdKQ_5OCtTuZBsv2nA9jW1oLWvy77r0hb1CQIZCL/s943/insert%20macro%20button.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Insert macro button&quot; border=&quot;0&quot; data-original-height=&quot;465&quot; data-original-width=&quot;943&quot; height=&quot;198&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8PLX7Ta32DW6Rabnz-UZ-EvfFOx_NPJwwPREypKfPhxa0BqCnqdzHPVidZucPqaMhvN9SogMchKIzJ1_MHL5ZKNlcMKAUnw2f2TtPqoEuT4I-2UierI3zOUVbQwxojgrkOKq4KyRRv8GncvtfTQY4rdKQ_5OCtTuZBsv2nA9jW1oLWvy77r0hb1CQIZCL/w400-h198/insert%20macro%20button.png&quot; title=&quot;Insert macro button&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGney35s7aNWuguoJHXXKmFITqNfjmXBOa0Q5ItAxVdlAzbp5o_HvkmvJpXPK4uYAibIB0u1JD8IUFcOuIc0ClB5Q81FDwrO-rkbvqSBNmTX0zEvWaWpL4CXabJdLn8T45Hqd0LU9IGhnIchaaFhJ5-YDsayQ_TmKWeMEj1GozUB5iM__0W9Sm8lYK05qq/s539/button%20to%20run%20macro%20in%20excel.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Button to run macro&quot; border=&quot;0&quot; data-original-height=&quot;241&quot; data-original-width=&quot;539&quot; height=&quot;179&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGney35s7aNWuguoJHXXKmFITqNfjmXBOa0Q5ItAxVdlAzbp5o_HvkmvJpXPK4uYAibIB0u1JD8IUFcOuIc0ClB5Q81FDwrO-rkbvqSBNmTX0zEvWaWpL4CXabJdLn8T45Hqd0LU9IGhnIchaaFhJ5-YDsayQ_TmKWeMEj1GozUB5iM__0W9Sm8lYK05qq/w400-h179/button%20to%20run%20macro%20in%20excel.png&quot; title=&quot;run macro using button in excel&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Now just click your button, and the macro will run automatically!&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Practice Makes Perfect! Download Your Excel Exercise Sheet&lt;/h2&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Learning how to combine columns in Excel is one thing… but practicing it? That’s where the real magic happens.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;I’ve put together an exercise sheet just for you! Inside, you’ll find ready-made data to practice:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Simple &amp;amp; formulas&lt;/li&gt;&lt;li&gt;TEXTJOIN() and CONCAT() methods&lt;/li&gt;&lt;li&gt;Flash Fill tricks&lt;/li&gt;&lt;li&gt;Even a spot to run your first VBA macro!&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Click below to download your practice workbook (it’s free!):&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;https://docs.google.com/spreadsheets/d/1qVgZi5gf7nFAor8druba4jRccnAbt4UN/edit?usp=sharing&amp;amp;ouid=105713709239976679085&amp;amp;rtpof=true&amp;amp;sd=true&quot; target=&quot;_blank&quot;&gt;Download the Excel Exercise Sheet Now!&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;(It’s a .xlsx file, totally safe, and won’t ask for your email.)&lt;/p&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;What’s Inside the Exercise Sheet?&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here’s a sneak peek of what you’ll get:&lt;/p&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;First Names and Last Names&lt;/b&gt; in Columns C and D to practice combining into Column E&lt;/li&gt;&lt;li&gt;Tasks for:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Combining columns with a &lt;b&gt;space, comma, or dash.&lt;/b&gt;&lt;/li&gt;&lt;li&gt;Ignoring blank cells using TEXTJOIN()&lt;/li&gt;&lt;li&gt;Creating full names with &lt;b&gt;prefixes/suffixes&lt;/b&gt;&lt;/li&gt;&lt;li&gt;Running a simple &lt;b&gt;VBA macro&lt;/b&gt; to automate the process&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;A &lt;b&gt;step-by-step guide&lt;/b&gt; right in the sheet so you won’t get lost!&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;How to Use It&lt;/b&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Download the file&lt;/b&gt; and open it in Excel.&lt;/li&gt;&lt;li&gt;Start with &lt;b&gt;Sheet 1&lt;/b&gt;, where you’ll practice basic formulas.&lt;/li&gt;&lt;li&gt;Move to the &lt;b&gt;Advanced Methods&lt;/b&gt; sheet for TEXTJOIN(), CONCAT(), and VBA.&lt;/li&gt;&lt;li&gt;Challenge yourself by solving the &lt;b&gt;Bonus Tasks&lt;/b&gt; I’ve included!&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Why Practice With This Sheet?&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;It’s hands-on, not just theory&lt;/li&gt;&lt;li&gt;You can &lt;b&gt;see the formulas in action&lt;/b&gt;&lt;/li&gt;&lt;li&gt;Perfect if you want to &lt;b&gt;learn by doing&lt;/b&gt;&lt;/li&gt;&lt;li&gt;Helps build &lt;b&gt;muscle memory&lt;/b&gt;, so combining columns becomes second nature!&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Quick Tips to Keep in Mind&lt;/h2&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Customize your separator&lt;/b&gt;: Use a comma, hyphen, dash, or anything else. Just replace the &quot; &quot; with whatever you need.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Lock the combined values&lt;/b&gt;: If you want to get rid of formulas, copy Column E, then right-click and choose Paste Values.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Works with numbers too&lt;/b&gt;: Combine product codes, IDs, anything.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Wrapping Up&lt;/h2&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Combining two columns in Excel is easy once you know how. Whether you’re merging names, product details, or anything else, these quick tricks can save you a ton of time.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Next time you’re cleaning up a spreadsheet, give these methods a try!&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;And if you want more time-saving Excel tips, let me know—I’d love to share more.&lt;/p&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2025/03/how-to-combine-two-columns-in-excel.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZe30yV6c-3QdZnli5pyw5WxDTAfBy4YY5PdxjQQWPh4djB-ep7h2ea1ZWgswDKUsWnISzm64QUtmF32udub3SlaIcbtQpZMU0LT6gF68ev2n-sMXwGLsfg491HzWgECQcZg19fELim1_lvYEqUEZ50v7EH5sZyXyeMUZqAEPxQFYYHsPQVGqVICKzP1cV/s72-w320-h170-c/Combine%20Two%20Columns%20in%20Excel%20with%20space.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-6679722917068728024</guid><pubDate>Thu, 13 Mar 2025 04:41:00 +0000</pubDate><atom:updated>2025-03-12T21:41:40.013-07:00</atom:updated><title>Partial Link Text in Selenium: When and How to Use It Effectively</title><description>&lt;p&gt;Are you trying to locate a hyperlink by linkText, but it doesn&#39;t work in Selenium automation?&amp;nbsp;&lt;b&gt;You’re not alone&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;If the &lt;b&gt;text of the link is changing dynamically&lt;/b&gt;, then &lt;b&gt;linkText doesn&#39;t work&lt;/b&gt; as it will look for the exact text of the hyperlink.&lt;/p&gt;&lt;p&gt;Here is the solution for this problem.&amp;nbsp;&lt;/p&gt;&lt;p&gt;You can use&amp;nbsp;&lt;b&gt;partial link text&lt;/b&gt; instead of the linkText element locator to locate such dynamic generated hyperlinks.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLIQG_cDej5eOLV5s10Inb4si7-eD_SsuSXE0a6zJT6V-Pf5NdXs9E_SDIVwwPgOZtOJP-xKXejnXNVvZ4p77lcvrrSO_oyXUdWUU5sO_TMpF9_m6lmM_lqnOI0xJ_0rZW3oO8GDKxJ_dG5W3j-04IALsohAFpTnJJoswXTWbGhjaI5iyrhyfH43fhIMWf/s618/use%20of%20partial%20link%20text%20in%20selenium%20webdriver.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Use of partial link text in selenium&quot; border=&quot;0&quot; data-original-height=&quot;286&quot; data-original-width=&quot;618&quot; height=&quot;185&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLIQG_cDej5eOLV5s10Inb4si7-eD_SsuSXE0a6zJT6V-Pf5NdXs9E_SDIVwwPgOZtOJP-xKXejnXNVvZ4p77lcvrrSO_oyXUdWUU5sO_TMpF9_m6lmM_lqnOI0xJ_0rZW3oO8GDKxJ_dG5W3j-04IALsohAFpTnJJoswXTWbGhjaI5iyrhyfH43fhIMWf/w400-h185/use%20of%20partial%20link%20text%20in%20selenium%20webdriver.png&quot; title=&quot;Learn how to use partiallinktext in selenium webdriver&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;This article will teach you what partial link text is, how and when to use&amp;nbsp;partial link text in Selenium automation.&lt;p&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;What is partial link text in Selenium WebDriver?&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/By.ByPartialLinkText.html&quot; target=&quot;_blank&quot;&gt;ByPartialLinkText&lt;/a&gt; is a static inner class inside the By class.&lt;/p&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It extends By and implements the locator strategy to find elements by partial link text.&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;To understand it easily, the partialLinkText is a&amp;nbsp;&lt;b&gt;locator strategy&lt;/b&gt; in Selenium WebDriver that allows you to locate &lt;b&gt;anchor elements&lt;/b&gt; (&amp;lt;a&amp;gt; tags) by matching a &lt;b&gt;part of the visible text&lt;/b&gt; of the hyperlink. that&#39;s it.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Why Use partialLinkText?&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Using partial link text, you do not need&amp;nbsp;full link text to identify the element.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; margin: 0px; padding: 0px;&quot;&gt;I use it when the&amp;nbsp;&lt;strong&gt;link text is too long&lt;/strong&gt;,&amp;nbsp;&lt;strong&gt;the text changes dynamically&lt;/strong&gt;, or&amp;nbsp;&lt;strong&gt;part of the text is predictable&lt;/strong&gt;.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Another reason why I am using it is that it&amp;nbsp;&lt;b&gt;makes my tests more flexible&lt;/b&gt;.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;How It Works&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;When you use it in an automation test, Selenium will&amp;nbsp;scan the DOM for &amp;lt;a&amp;gt; elements. It will check for visible text (between &amp;lt;a&amp;gt; and &amp;lt;/a&amp;gt;) that contains the substring that you have specified in code.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;For example, consider the following HTML of a hyperlink.&lt;/p&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&amp;lt;a href=&quot;https://example.com&quot;&amp;gt;Learn Selenium with Examples&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If you are working with Java Selenium, you can locate this link using:&lt;/p&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;WebElement link = driver.findElement(By.partialLinkText(&quot;Learn Selenium&quot;));&lt;/span&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;or&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;WebElement link = driver.findElement(By.partialLinkText(&quot;with Examples&quot;));&lt;/span&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;PartialLinkText syntax for Python Selenium is:&lt;/p&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;link = driver.find_element(By.PARTIAL_LINK_TEXT, &quot;with Examples&quot;)&lt;/span&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and for C# is:&lt;/p&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;IWebElement link = driver.FindElement(By.PartialLinkText(&quot;with Examples&quot;));&lt;/span&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Let me clarify that it works with&amp;nbsp;anchor tags (&amp;lt;a&amp;gt;) only. So, do not try to locate other web elements like button, &amp;lt;button&amp;gt;, textbox, &amp;lt;input&amp;gt;, etc. using&amp;nbsp;partial link text. It will not work with them.&lt;/p&gt;&lt;p&gt;Is it clear now? I think so.&lt;/p&gt;&lt;p&gt;Now let&#39;s dive into the examples..&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Using PartialLinkText In Selenium: Step by Step&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If you are a beginner, this step-by-step guide will help you understand how to use partial link text practically.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Step 1: Set up and configure Selenium in Eclipse&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;This guide will help you to understand &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2013/08/how-to-download-and-install-selenium.html&quot; target=&quot;_blank&quot;&gt;how to download and install Selenium WebDriver&lt;/a&gt; in Eclipse IDE.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Step 2: Download and install Chrome Driver&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;I have already written a step-by-step tutorial on &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/02/chrome-driver-download-for-selenium.html&quot; target=&quot;_blank&quot;&gt;how to download and install&amp;nbsp;Chrome Driver&lt;/a&gt;. You can refer to it.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Step 3: Create a project &amp;amp; write a code in Eclipse&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can create a new project and write the following code in the class file.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Before running this code, remember to replace the &lt;b&gt;Chrome driver path&lt;/b&gt;, the &lt;b&gt;test URL&lt;/b&gt;, and the &lt;b&gt;link text&lt;/b&gt; with your actual one.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Java Example Code&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class PartialLinkTextExample {
    public static void main(String[] args) {

        // Set the path to your ChromeDriver executable if necessary
        // System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;path/to/chromedriver&quot;);

        // Initialize ChromeDriver (Selenium 4 style)
        WebDriver driver = new ChromeDriver();

        // Open a webpage
        driver.get(&quot;https://example.com&quot;);

        // Locate the &amp;lt;a&amp;gt; element using partialLinkText
        WebElement link = driver.findElement(By.partialLinkText(&quot;Learn&quot;));

        // Click the link
        link.click();

        // Close the browser
        driver.quit();
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;Step 4: Run the code&lt;/b&gt;&lt;/p&gt;&lt;p&gt;When you run the above code, it will open the Chrome browser, navigate to your given URL, locate an element by partial link text, click on it, and then close the browser.&lt;/p&gt;&lt;p&gt;Are you working in &lt;b&gt;Python or C#&lt;/b&gt;? Don&#39;t worry. I have examples in both these languages as well.&lt;/p&gt;&lt;p&gt;Here they are:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Python Example Code&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;from selenium import webdriver
from selenium.webdriver.common.by import By

# Initialize the driver (Selenium 4 style)
driver = webdriver.Chrome()

driver.get(&quot;https://example.com&quot;)

# Find an &amp;lt;a&amp;gt; element containing &quot;Learn&quot; in its text
link = driver.find_element(By.PARTIAL_LINK_TEXT, &quot;Learn&quot;)

# Perform click action
link.click()

# Close the driver
driver.quit()&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;C# Example Code&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

class Program
{
    static void Main(string[] args)
    {
        IWebDriver driver = new ChromeDriver();

        driver.Navigate().GoToUrl(&quot;https://example.com&quot;);

        // Locate &amp;lt;a&amp;gt; element with partial link text &quot;Learn&quot;
        IWebElement link = driver.FindElement(By.PartialLinkText(&quot;Learn&quot;));

        // Click the link
        link.Click();

        // Close the browser
        driver.Quit();
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So, that&#39;s it on how to &lt;b&gt;use partialLinkText in selenium&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;But you should know how to use it efficiently, right?&lt;/p&gt;&lt;p&gt;Let&#39;s jump on best practices.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Best Practices for Using partialLinkText&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here are some important things to consider to prevent errors and improve test execution performance.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Use Unique Substrings&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Always prefer using a unique substring. If text is changing frequently, your test will fail. This is a very very important point.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Avoid Common Words&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;We generally find common words like &quot;Click&quot; and &quot;More&quot; many times on the page. Avoid using such words to locate an element by partial link text.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Prefer linkText When You Know the Full Link Text&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If text is unique and static, then you can use the &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/linktext-selenium.html&quot; target=&quot;_blank&quot;&gt;linkText locator&lt;/a&gt;.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Interview Tip!&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If the interviewer asks you a question, &quot;When would you use partialLinkText over other locators?&quot;&lt;/p&gt;&lt;p&gt;You can say: When I need to locate a link with long or dynamic visible text, and I know a unique part of that text, I use partialLinkText. It simplifies the locator and avoids brittle XPath expressions.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Winding Up&lt;/h2&gt;&lt;p&gt;In summary, partialLinkText is a handy locator strategy in Selenium WebDriver when you need to interact with hyperlinks by matching only a portion of their visible text.&lt;/p&gt;&lt;p&gt;That&#39;s it. Any question or query? You can ask me your doubt by commenting below.&lt;/p&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2025/03/partial-link-text-in-selenium.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLIQG_cDej5eOLV5s10Inb4si7-eD_SsuSXE0a6zJT6V-Pf5NdXs9E_SDIVwwPgOZtOJP-xKXejnXNVvZ4p77lcvrrSO_oyXUdWUU5sO_TMpF9_m6lmM_lqnOI0xJ_0rZW3oO8GDKxJ_dG5W3j-04IALsohAFpTnJJoswXTWbGhjaI5iyrhyfH43fhIMWf/s72-w400-h185-c/use%20of%20partial%20link%20text%20in%20selenium%20webdriver.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-6576608028555184045</guid><pubDate>Tue, 11 Mar 2025 11:14:00 +0000</pubDate><atom:updated>2025-03-11T05:50:17.614-07:00</atom:updated><title>What is linkText in Selenium? Ultimate Guide for Beginners</title><description>&lt;p&gt;&amp;nbsp;Do you know how to click on the link without using&amp;nbsp;complicated locators like XPath and CSS selectors? &lt;b&gt;linkText in Selenium&lt;/b&gt; is a specially designed element locator that locates and interacts with hyperlinks on a page. Whether you are just starting out or looking to use it effectively in your selenium tests, this guide will help you understand how Link Text works, when to use it, and a few tips to make your automation scripts cleaner and more reliable.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;What is linkText in Selenium?&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/By.ByLinkText.html&quot;&gt;ByLinkText&lt;/a&gt; is a&amp;nbsp;&lt;b&gt;concrete class inside the By class&lt;/b&gt; in Selenium. It is responsible for finding elements by the exact visible link text.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;In simple words,&amp;nbsp;linkText is a locator strategy in Selenium WebDriver that is used to identify hyperlinks (&amp;lt;a&amp;gt; tags) on a web page by their exact visible text.&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;How It Works behind the scenes:&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;When you use this Selenium locator in a test, it will search for an &lt;b&gt;&amp;lt;a&amp;gt; tag&lt;/b&gt; whose text content exactly matches the string you pass.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If Selenium finds a hyperlink with matching text, it will interact with it to perform your given task like click on it, get text, etc.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;When to Use&lt;/h3&gt;&lt;div&gt;You can use it when:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;link text is unique on the page.&lt;/li&gt;&lt;li&gt;It is static and doesn’t change dynamically.&lt;/li&gt;&lt;li&gt;You are looking for a quick and easy way to locate a hyperlink.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Syntax of linkText&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;I don&#39;t know in which language you are working. &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/selenium-supported-languages.html&quot; target=&quot;_blank&quot;&gt;Selenium supports multiple languages.&lt;/a&gt; So I am providing link text locator syntax for popular languages, Java, Python, and C#.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Java Syntax&lt;/h3&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;driver.findElement(By.linkText(&quot;Exact Link Text&quot;)).click();
&lt;/span&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Python Syntax&lt;/h3&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;driver.find_element(By.LINK_TEXT, &quot;Exact Link Text&quot;).click()&lt;/span&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;C# Syntax&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;driver.FindElement(By.LinkText(&quot;Exact Link Text&quot;)).Click();&lt;/span&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;span style=&quot;font-size: 24px; white-space: normal;&quot;&gt;&lt;b&gt;&lt;span&gt;
&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Step-by-Step: Using linkText in Selenium&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here is a &lt;b&gt;step-by-step guide&lt;/b&gt; on how to use link text element locator in Selenium WebDriver.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Step 1: Set Up Selenium WebDriver&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Make sure that selenium is installed and configured properly in your project. If not configured, you can follow these &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2013/08/how-to-download-and-install-selenium.html&quot; target=&quot;_blank&quot;&gt;Selenium installation guidelines&lt;/a&gt;.&lt;/p&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;// Import necessary Selenium packages
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Step 2: Update Chrome Browser and Download Latest ChromeDriver&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;For beginners, it is recommended to run initial tests on the Chrome browser. So, update your Chrome browser to the latest version and download the latest version of ChromeDriver. Here is a guideline to &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/02/chrome-driver-download-for-selenium.html&quot; target=&quot;_blank&quot;&gt;download the latest version of ChromeDriver&lt;/a&gt; and update the Chrome browser.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If you are using the Edge browser, here is a guide on&amp;nbsp;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/edge-driver-download-for-selenium.html&quot;&gt;how to download the latest EdgeDriver&lt;/a&gt; for Selenium.&lt;/p&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Step 3: Launch the Browser&lt;/h3&gt;&lt;/div&gt;&lt;p&gt;Create a WebDriver instance and open a browser (like Chrome).&lt;/p&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;// Set up ChromeDriver path (optional depending on your setup)
System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;path/to/chromedriver&quot;);

// Launch Chrome browser
WebDriver driver = new ChromeDriver();&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Step 4: Navigate to the Web Page&lt;/h3&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Open the website where you want to click a link. We will use an example link. You can replace it with your testing URL.&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;driver.get(&quot;https://example.com&quot;);&lt;/span&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Step 5: Locate the Link by Its Text and Click on It&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Use By.linkText() method to find the link with the exact visible text and&amp;nbsp;click() method to click on it. You need to replace link text, i.e. &quot;Exact Link Text&quot; as per your original link text.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;//Locate link by exact link text
WebElement yourLinkText = driver.findElement(By.linkText(&quot;Click Here&quot;));

//click on link
yourLinkText.click();&lt;/span&gt;&lt;span style=&quot;font-family: arial; font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;The above code will locate and click on the link.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiddgoAgBMuZwag6LB8V4fRem43U-JZVJFh-AmJ937D3764d71ymYqZjJ9QrZqeVvhSgHCPSEpSzqm0t-I0qk4y74XBkf5DJbVeHZj7qnNgLIMaXlhh64JVwhf_aU_9o63PoLT3XlVIpqJRAgRPeni-UyZ_H0shH47zthfrw9-jJ_UvTrS7b04iuxLpAxak/s466/locator%20linktext%20in%20selenium.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;linkText locator in selenium&quot; border=&quot;0&quot; data-original-height=&quot;351&quot; data-original-width=&quot;466&quot; height=&quot;301&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiddgoAgBMuZwag6LB8V4fRem43U-JZVJFh-AmJ937D3764d71ymYqZjJ9QrZqeVvhSgHCPSEpSzqm0t-I0qk4y74XBkf5DJbVeHZj7qnNgLIMaXlhh64JVwhf_aU_9o63PoLT3XlVIpqJRAgRPeni-UyZ_H0shH47zthfrw9-jJ_UvTrS7b04iuxLpAxak/w400-h301/locator%20linktext%20in%20selenium.png&quot; title=&quot;Click on hyper link using linktext locator in selenium webdriver automation test&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Tips&lt;/b&gt;:&amp;nbsp;&lt;/p&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Exact Text Match&lt;/b&gt;: It is case-sensitive. Also make sure you are using exact text.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Only for &amp;lt;a&amp;gt; Tags&lt;/b&gt;: This locator strategy works only with anchor tags (&amp;lt;a&amp;gt; elements).&lt;/li&gt;&lt;li&gt;&lt;b&gt;Avoid Extra Spaces&lt;/b&gt;: Remove&amp;nbsp;leading/trailing whitespace from text.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Use partialLinkText()&lt;/b&gt;: If you know only part text of the link, use&amp;nbsp;partialLinkText() instead of linkText().&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Common Use Cases:&lt;/b&gt;&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can use this method for the below given real world test scenarios.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Navigating to different pages through hyperlinks.&lt;/li&gt;&lt;li&gt;Clicking buttons styled as links.&lt;/li&gt;&lt;li&gt;Automating simple workflows with clickable link text.&lt;/li&gt;&lt;/ul&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;linkText examples in Java, Python, and C# for Selenium WebDriver&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here is a basic example code for learners on how to use linkText in Java, Python, and C# languages.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Note&lt;/b&gt;: Please replace chromedriver path, test URL, and link text with your own ones before running any of the below given examples.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Java Example&lt;/b&gt;&lt;/h4&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class LinkTextExample {
    public static void main(String[] args) {

        // Set path to chromedriver if necessary
        System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;path/to/chromedriver&quot;);

        // Initialize the ChromeDriver
        WebDriver driver = new ChromeDriver();

        try {
            // Open the webpage
            driver.get(&quot;https://example.com&quot;);

            // Find the link by its exact text and click it
            WebElement link = driver.findElement(By.linkText(&quot;Contact Us&quot;));
            link.click();

        } finally {
            // Close the browser
            driver.quit();
        }
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Python Example&lt;/b&gt;&lt;/h4&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;from selenium import webdriver
from selenium.webdriver.common.by import By

# Initialize the Chrome driver
driver = webdriver.Chrome()

try:
    # Open the webpage
    driver.get(&quot;https://example.com&quot;)

    # Find the link by its exact text and click it
    link = driver.find_element(By.LINK_TEXT, &quot;Contact Us&quot;)
    link.click()

finally:
    # Close the browser
    driver.quit()&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;C# Example&lt;/b&gt;&lt;/h4&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

class LinkTextExample
{
    static void Main(string[] args)
    {
        // Initialize ChromeDriver
        IWebDriver driver = new ChromeDriver();

        try
        {
            // Open the webpage
            driver.Navigate().GoToUrl(&quot;https://example.com&quot;);

            // Find the link by its exact text and click it
            IWebElement link = driver.FindElement(By.LinkText(&quot;Contact Us&quot;));
            link.Click();
        }
        finally
        {
            // Close the browser
            driver.Quit();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;The above examples will demonstrate to you how to use the linkText element locator to click on a link.&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Handling&amp;nbsp;Multiple Links with Identical Link Text&lt;/h2&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If Selenium will find multiple links with the same link text on the page, it&amp;nbsp;will only return the first matching element.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Example Scenario:&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Suppose a page has hyperlinks like below.&lt;/p&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&amp;lt;a href=&quot;https://example.com/pagex&quot;&amp;gt;View Product&amp;lt;/a&amp;gt;
&amp;lt;a href=&quot;https://example.com/pagey&quot;&amp;gt;View Product&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;a href=&quot;https://example.com/pagez&quot;&amp;gt;View Product&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOBik3iaQshfHwlJ_GqA96HPwxUMln0Q16kCNnUrqrp0PSseWzehEmGGde_yDIt-MxYlL4nreI4msTZhVi8dDyuHcgjz69h-3DMe1itiAiRv3XHJ2dLNj__St6ZwoZBs4jqZQKNqFyUn3DVTAZHsYTYBErUaePHbVL7bUFaK3vj9y7BJEbqPfUARJxUrFv/s550/handle%20multiple%20links%20in%20linktext%20element%20locator.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;handle multiple links using linktext&quot; border=&quot;0&quot; data-original-height=&quot;176&quot; data-original-width=&quot;550&quot; height=&quot;127&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOBik3iaQshfHwlJ_GqA96HPwxUMln0Q16kCNnUrqrp0PSseWzehEmGGde_yDIt-MxYlL4nreI4msTZhVi8dDyuHcgjz69h-3DMe1itiAiRv3XHJ2dLNj__St6ZwoZBs4jqZQKNqFyUn3DVTAZHsYTYBErUaePHbVL7bUFaK3vj9y7BJEbqPfUARJxUrFv/w400-h127/handle%20multiple%20links%20in%20linktext%20element%20locator.png&quot; title=&quot;clicking on specific link using linktext element locator in selenium&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If you run this in Selenium:&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;WebElement link = driver.findElement(By.linkText(&quot;View Product&quot;));
link.click();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Selenium will click only the first &amp;lt;a&amp;gt; element:&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&amp;lt;a href=&quot;https://example.com/pagex&quot;&amp;gt;View Product&amp;lt;/a&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;When multiple links are present on the page, and if you want to click on the second link, then you can use the following code.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;// Find all links with the exact link text
List&amp;lt;WebElement&amp;gt; links = driver.findElements(By.linkText(&quot;View Product&quot;));

// Click the second link (index 1, since list is zero-based)
if (links.size() &amp;gt;= 2) {
    links.get(1).click();
} else {
    System.out.println(&quot;Second link not found!&quot;);
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Here, we have used the findElements method to get a list of links from the page with the View Product text. Then the code will check if more than two links are present in the list, then it will kick on the second link using the index value.&lt;/p&gt;&lt;p&gt;However, it is advised to &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/xpath-in-selenium.html&quot;&gt;use XPath &lt;/a&gt;i.e.&amp;nbsp;By.xpath(&quot;(//a[text()=&#39;View Product&#39;])[2]&quot;) if multiple links with the same text are present on the page and you want to click on a specific link.&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If you want to click on all three links, you can use a for loop to iterate and click on them one by one, as the example below.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;List&amp;lt;WebElement&amp;gt; links = driver.findElements(By.linkText(&quot;View Product&quot;));

for (WebElement link : links) {
    System.out.println(link.getAttribute(&quot;href&quot;)); // Prints each link&#39;s URL
    // link.click();  // Optional: Click each link (but be cautious, as clicking may navigate away)
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Pro Tip!&lt;/b&gt;: Do not use&amp;nbsp;linktext locator in Selenium if&amp;nbsp;text of link changes frequently. Instead you can use&amp;nbsp;partialLinkText,&amp;nbsp;XPath, or CSS selectors.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;h2&gt;Real world Examples&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Using the link text element locator, you can not only click on the link. But you can use it for many &lt;b&gt;different purposes&lt;/b&gt;. Here are practical examples on how and when you can use &lt;b&gt;linkText in Selenium automation&lt;/b&gt;.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Example 1: Extract and Print the Link Text&lt;/h3&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can get and print the text of a link to verify if it&#39;s correct.&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;// Find the link element
WebElement link = driver.findElement(By.linkText(&quot;About Us&quot;));

// Get the visible text of the link
String linkText = link.getText();

// Print the link text
System.out.println(&quot;Link Text is: &quot; + linkText);&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Example 2: Retrieve the URL (href Attribute) of the Link&lt;/h3&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can fetch the href value to verify if the URL is correct or not.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;WebElement link = driver.findElement(By.linkText(&quot;Contact Us&quot;));

// Get the &#39;href&#39; attribute value (the destination URL)
String linkURL = link.getAttribute(&quot;href&quot;);

System.out.println(&quot;The link points to: &quot; + linkURL);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3&gt;Example 3: Count How Many Links Are on the Page with Specific Text&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can find out how many times a link with a specific text appears on a page.&lt;/p&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;List&amp;lt;WebElement&amp;gt; links = driver.findElements(By.linkText(&quot;Click here&quot;));

System.out.println(&quot;Number of &#39;Cclick here&#39; links: &quot; + links.size());
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3&gt;Example 4:&amp;nbsp;Verify If a Specific Link Is Displayed/Enabled&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can check if a link is visible or enabled on the page before performing actions.&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;WebElement link = driver.findElement(By.linkText(&quot;Terms of Service&quot;));

if(link.isDisplayed() &amp;amp;&amp;amp; link.isEnabled()) {
    System.out.println(&quot;The link is visible and clickable.&quot;);
} else {
    System.out.println(&quot;The link is not ready to interact with.&quot;);
}
&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Example 5:&amp;nbsp;Validate Broken Links Without Clicking&lt;/h3&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can use it to locate a link and then send an HTTP request to the href URL to check if the link is broken or working.&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;WebElement link = driver.findElement(By.linkText(&quot;About Us&quot;));

String linkURL = link.getAttribute(&quot;href&quot;);

// (Assume you have an HTTP client here)
if(checkIfLinkIsBroken(linkURL)) {
    System.out.println(&quot;The link is broken: &quot; + linkURL);
} else {
    System.out.println(&quot;The link works fine!&quot;);
}
&lt;/code&gt;&lt;/pre&gt;&lt;p style=&quot;text-align: left;&quot;&gt;So this way, you can use it for different purposes.&lt;/p&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Difference Between linkText and partialLinkText&lt;/h2&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Main difference between link text and partial link text is: &lt;b&gt;linkText matches the full visible text&lt;/b&gt; of the link while&amp;nbsp;&lt;b&gt;partialLinkText matches part of the link text&lt;/b&gt;. linkText is a strict element locator, but partialLinkText is&amp;nbsp;more flexible.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Advantages:&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here is a list of advantages of using linktext locator in Selenium automation.&lt;/p&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Simple and Readable&lt;/b&gt;: It is very simple to understand.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Precise&lt;/b&gt;: Very useful locator when the link text is unique.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Direct&lt;/b&gt;:&amp;nbsp;No need to deal with complex locators like XPath or CSS.&lt;/li&gt;&lt;/ul&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Limitations:&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Please consider these limitations before using linktext locator in your automation tests.&lt;/p&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Exact Match Required&lt;/b&gt;: If the text of the link changes or has a leading/trailing space, it can fail.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Case-Sensitive&lt;/b&gt;: Some browsers treat links differently. Use the same link text as per actual on the page.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Not for Partial Matches&lt;/b&gt;: It doesn’t work if you only know part of the text.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Best Practices&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Follow these best practices for better performance in Selenium automation when using link text.&lt;/p&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Ensure Uniqueness: Make sure the link text is unique on the page.&lt;/li&gt;&lt;li&gt;Avoid Long or Dynamic Texts: If the link text is long or dynamic, prefer to use partialLinkText, XPath, or CSS Selectors.&lt;/li&gt;&lt;li&gt;Trim Spaces: Remove extra spaces in the text.&lt;/li&gt;&lt;li&gt;Localization: Avoid linkText for multilingual pages.&lt;/li&gt;&lt;/ul&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Final Words&lt;/h2&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;linkText is a simple and beginner-friendly locator strategy in Selenium WebDriver. It’s highly effective when you need to interact with hyperlinks that have clear, static, and unique visible text.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2025/03/linktext-selenium.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiddgoAgBMuZwag6LB8V4fRem43U-JZVJFh-AmJ937D3764d71ymYqZjJ9QrZqeVvhSgHCPSEpSzqm0t-I0qk4y74XBkf5DJbVeHZj7qnNgLIMaXlhh64JVwhf_aU_9o63PoLT3XlVIpqJRAgRPeni-UyZ_H0shH47zthfrw9-jJ_UvTrS7b04iuxLpAxak/s72-w400-h301-c/locator%20linktext%20in%20selenium.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-7653781146813882344</guid><pubDate>Mon, 10 Mar 2025 13:12:00 +0000</pubDate><atom:updated>2025-03-11T04:18:17.970-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">tag name</category><title>TagName Locator in Selenium WebDriver: Everything You Need to Know</title><description>&lt;p&gt;Element locators play an important part in interacting with elements in Selenium tests. Let me clarify here that Selenium supports lots of element locators like &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/find-element-by-id-in-selenium.html&quot; target=&quot;_blank&quot;&gt;ID&lt;/a&gt;, &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/name-locator-in-selenium.html&quot; target=&quot;_blank&quot;&gt;Name&lt;/a&gt;, XPath, CSS Selectors, tagName, &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/linktext-selenium.html&quot; target=&quot;_blank&quot;&gt;linkText&lt;/a&gt;, partialLinkText. All the element locators have their own advantages and disadvantages. Let us see what the tagName locator in Selenium, how it works, and when to use it in real-time test automation scenarios.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;What is TagName Locator in Selenium?&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/By.ByTagName.html&quot;&gt;By.ByTagName&lt;/a&gt; is an inner static class inside the By class in Selenium. It&amp;nbsp;represents the By.tagName(String tagName) locator strategy.&lt;/p&gt;&lt;p&gt;TagName locator is a simple and very powerful element locator in Selenium. One can use it to locate an element by&amp;nbsp;HTML tags such as &amp;lt;input&amp;gt;, &amp;lt;a&amp;gt;, &amp;lt;div&amp;gt;, &amp;lt;button&amp;gt;, &amp;lt;h1&amp;gt;, etc. It allows to&amp;nbsp;interact with all the links on a page or loop through rows in a table. Also, you can use it to&amp;nbsp;find elements of a specific tag type,&amp;nbsp;either a single element or a group of them.&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;When and Why to Use TagName Locator?&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;There are many other power locators available in Selenium. So why or when to use the tagname locator?&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here are some real world scenarios where you can prefer to use it instead of other element locators.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Count the number of elements on the page using the tag name&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Suppose you have a test scenario or requirement to count how many links or buttons are present on a page. You can count it easily using the tag name locator.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here is an example in Java&lt;/p&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt; &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;// Find all elements with tag name &#39;a&#39;
        List&amp;lt;WebElement&amp;gt; links = driver.findElements(By.tagName(&quot;a&quot;));

        // Count the number of &#39;a&#39; tags
        int count = links.size();

        // Print the count
        System.out.println(&quot;Number of &amp;lt;a&amp;gt; tags on the page: &quot; + count);&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;In the above example,&amp;nbsp;findElements(By.tagName(&quot;a&quot;)) will find all elements with the &amp;lt;a&amp;gt; tag and&amp;nbsp;size() gives the count of those elements.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;When other element locators are not available&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Sometimes, elements do not have any attribute but have a tag name only. In this case, it is easy to locate the element based on its tag name instead of slower element locators like &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/xpath-in-selenium.html&quot; target=&quot;_blank&quot;&gt;XPath &lt;/a&gt;and CSS selectors.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Easy to find the child&amp;nbsp;elements&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can use it to find a child element which is located inside a parent element, such as getting all rows &amp;lt;tr&amp;gt; from a table.&lt;/p&gt;&lt;div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here is an example in Python to read data from the table using tag name.&lt;/p&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;# Locate the table (optional if you want to focus on a specific table)
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;table = driver.find_element(By.ID, &quot;customers&quot;)

&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;# Find all rows (&amp;lt;tr&amp;gt;) inside the table
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;rows = table.find_elements(By.TAG_NAME, &quot;tr&quot;)

&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;# Print the number of rows
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;print(f&quot;Total number of rows: {len(rows)}&quot;)

&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;# Optional: Print the text in each row
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;for index, row in enumerate(rows):
    print(f&quot;Row {index}: {row.text}&quot;)
&lt;/span&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p style=&quot;text-align: left;&quot;&gt;In this example, find_elements(By.TAG_NAME, &quot;tr&quot;) will find all the &amp;lt;tr&amp;gt; elements (rows) inside that table. Then&amp;nbsp;len(rows) will count the number of rows and&amp;nbsp;row.text will get the text content of each row.&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;How TagName Works (Behind the Scenes)&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;When you use&amp;nbsp;By.tagName() in Selenium test, it will search for your provided HTML tag name on the page&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;For example:&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&amp;lt;a href=&quot;https://example.com&quot;&amp;gt;Click Me&amp;lt;/a&amp;gt;
&lt;/span&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In this case,&amp;nbsp;if you use By.tagName(&quot;a&quot;), it finds the anchor element from the given HTML structure.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;How to find the Tag Name of an element from the page&lt;/h2&gt;&lt;p&gt;To find the tag name of the element, you can:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Right click on element.&lt;/li&gt;&lt;li&gt;Select inspect element.&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can get the tag name of the element as shown in the given image.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJSwYSkzor7H6UM0ZEJ6-5RhZBngWWQVhYZM9IRH9ZlxpMYpr5sabX8AT_VQZT3Z8CwyULP3BIzu7En00ms6glW8JbDg7lQB-SixfEVXecIEI0FL4pq9p-Re9yThhd3Im4yEJphLuVkZHElxrne7cYUOmaGyV0jRv00QThPBy5D5DMLcdNBAzQjTaQpnm_/s637/find%20tag%20name%20to%20use%20in%20selenium%20test.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Find tag name of element&quot; border=&quot;0&quot; data-original-height=&quot;364&quot; data-original-width=&quot;637&quot; height=&quot;366&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJSwYSkzor7H6UM0ZEJ6-5RhZBngWWQVhYZM9IRH9ZlxpMYpr5sabX8AT_VQZT3Z8CwyULP3BIzu7En00ms6glW8JbDg7lQB-SixfEVXecIEI0FL4pq9p-Re9yThhd3Im4yEJphLuVkZHElxrne7cYUOmaGyV0jRv00QThPBy5D5DMLcdNBAzQjTaQpnm_/w640-h366/find%20tag%20name%20to%20use%20in%20selenium%20test.png&quot; title=&quot;finding tag name of element using inspect element from page.&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Java, Python, and C# Syntax to use TagName Locator in Selenium&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Java syntax&lt;/p&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;//To find single element
WebElement element = driver.findElement(By.tagName(&quot;tagname&quot;));

//To find multiple elements
List&amp;lt;WebElement&amp;gt; elements = driver.findElements(By.tagName(&quot;tagname&quot;));
&lt;/code&gt;&lt;/pre&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Python syntax&lt;/p&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;//To find single element
element = driver.find_element(By.TAG_NAME, &quot;tagname&quot;)

//To find multiple elements
elements = driver.find_elements(By.TAG_NAME, &quot;tagname&quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;p&gt;C# syntax&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;//To find single element
IWebElement element = driver.FindElement(By.TagName(&quot;tagname&quot;));

//To find multiple elements
IReadOnlyCollection&amp;lt;IWebElement&amp;gt; elements = driver.FindElements(By.TagName(&quot;tagname&quot;));&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Practical Examples of Using TagName Locator&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here are some examples of using the tagName locator to understand it better.&lt;/p&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Example 1: Find a header tag using TagName&lt;/h3&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;// Find the first &amp;lt;h1&amp;gt; tag on the page
WebElement heading = driver.findElement(By.tagName(&quot;h1&quot;));
System.out.println(&quot;Heading Text: &quot; + heading.getText());
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;In this example, it will locate the first h1 tag using By.tagName(&quot;h1&quot;) and get the header text using&amp;nbsp;heading.getText() and print it in the console.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Example 2: Find All Links on a Web Page&lt;/h3&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;// Find all &amp;lt;a&amp;gt; tags (links)
List&amp;lt;WebElement&amp;gt; allLinks = driver.findElements(By.tagName(&quot;a&quot;));

System.out.println(&quot;Total Links: &quot; + allLinks.size());

for (WebElement link : allLinks) {
    System.out.println(link.getText() + &quot; - &quot; + link.getAttribute(&quot;href&quot;));
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;In the above example,&amp;nbsp;&lt;/span&gt;findElements(By.tagName(&quot;a&quot;)) will find all elements having tag name a. allLinks.size() will calculate how many links and print it in the console. The next for loop is used to extract link text using&amp;nbsp;link.getText() and print it in the console.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Example 3: Count All Input Fields on a Form&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;// Find all &amp;lt;input&amp;gt; fields
List&amp;lt;WebElement&amp;gt; inputFields = driver.findElements(By.tagName(&quot;input&quot;));

System.out.println(&quot;Number of input fields: &quot; + inputFields.size());
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can use the above example to calculate how many input fields are present on the page.&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Step by step how to use tagName in Selenium&lt;/h2&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Step 1: Download and install browser driver&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;First of all, you need to download the browser driver, i.e. ChromeDriver, to run tests in Chrome browser. Here is a guide on how to &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/02/chrome-driver-download-for-selenium.html&quot; target=&quot;_blank&quot;&gt;download and configure Selenium Chrome Driver&lt;/a&gt;.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Step 2: Download and Configure Selenium in your project&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Next step is to download and configure Selenium in your project. You can do it manually or use a Maven-like framework to set up Selenium. Here is step by step guide on &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2013/08/how-to-download-and-install-selenium.html&quot; target=&quot;_blank&quot;&gt;how to download and install&amp;nbsp; Selenium Webdriver with Eclipse&lt;/a&gt;.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Step 3 Launch browser and run test&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Now you can use the following examples to run tests in Java, Python, and C# languages. These examples will demonstrate how to use the tagName in Selenium tests.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;tagName Selenium Example in Java&lt;/b&gt;&lt;/p&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.List;

public class TagNameExample {
    public static void main(String[] args) {
        // Set the path to your chromedriver executable if needed
        System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;path/to/chromedriver&quot;);

        WebDriver driver = new ChromeDriver();

        // Step 3: Open a website
        driver.get(&quot;https://example.com&quot;);

        // Step 4: Find a single element by tag name
        WebElement firstParagraph = driver.findElement(By.tagName(&quot;p&quot;));
        System.out.println(&quot;First paragraph text: &quot; + firstParagraph.getText());

        // Step 5: Find multiple elements by tag name
        List&amp;lt;WebElement&amp;gt; allLinks = driver.findElements(By.tagName(&quot;a&quot;));
        System.out.println(&quot;Total links: &quot; + allLinks.size());

        // Step 6: Close browser
        driver.quit();
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;tagName Example in Python&lt;/b&gt;&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;from selenium import webdriver
from selenium.webdriver.common.by import By

# Step 1: Launch browser
driver = webdriver.Chrome()

# Step 2: Open a website
driver.get(&quot;https://example.com&quot;)

# Step 3: Find a single element by tag name
first_paragraph = driver.find_element(By.TAG_NAME, &quot;p&quot;)
print(&quot;First paragraph text:&quot;, first_paragraph.text)

# Step 4: Find multiple elements by tag name
all_links = driver.find_elements(By.TAG_NAME, &quot;a&quot;)
print(&quot;Total links found:&quot;, len(all_links))

# Step 5: Close browser
driver.quit()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;C# Example&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.ObjectModel;

class TagNameExample
{
    static void Main()
    {
        // Step 1: Launch browser
        IWebDriver driver = new ChromeDriver();

        // Step 2: Open a website
        driver.Navigate().GoToUrl(&quot;https://example.com&quot;);

        // Step 3: Find a single element by tag name
        IWebElement firstParagraph = driver.FindElement(By.TagName(&quot;p&quot;));
        Console.WriteLine(&quot;First paragraph text: &quot; + firstParagraph.Text);

        // Step 4: Find multiple elements by tag name
        ReadOnlyCollection&amp;lt;IWebElement&amp;gt; allLinks = driver.FindElements(By.TagName(&quot;a&quot;));
        Console.WriteLine(&quot;Total links found: &quot; + allLinks.Count);

        // Step 5: Close browser
        driver.Quit();
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Advantages of the tagName locator&lt;/h2&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here is a list of advantages of using tagName in your Selenium test.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Simple and Easy to Use&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It is&amp;nbsp;straightforward to locate elements by their HTML tag, like a, div, table, etc&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Useful for Bulk Element Retrieval&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Handy to&amp;nbsp;collections of elements with the same tag name, like:&amp;nbsp;&lt;/p&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;All links on a page (&amp;lt;a&amp;gt;)&lt;/li&gt;&lt;li&gt;All rows in a table (&amp;lt;tr&amp;gt;)&lt;/li&gt;&lt;li&gt;All images (&amp;lt;img&amp;gt;)&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Efficient for Common Scenarios&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can use the tag name locator when you are looking to loop through lists of similar elements, or&amp;nbsp;iterate over table rows or cells.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;No Need for Attributes&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Other locators like ID, name, Class name need an attribute and a value. But you just need an HTML tag to locate an element by tag name.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Lightweight Selector&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It is a lightweight selector compared to XPath and CSS selectors.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Limitations of TagName Locator&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Each and every locator has its own strength and limitations. Same way, finding by tagName has its own limitations as below.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Not Specific Enough&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Common tags like div, span, and a can appear many times, so&amp;nbsp;findElement() will return only the first matching element. Also, it is hard to target specific elements without combining it with other locators.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Limited Filtering&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Using tagName, direct filtering by attributes like id, class, name is not possible.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Can Return Empty Results&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;findElements() will return an empty list and findElement() will throw a NoSuchElementException if the tag is not present on the page.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;May Impact Performance&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If there are lots of matching tags on the same page, it is not advised to use tagName as a locator. It can impact performance.&lt;/p&gt;&lt;div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Frequently Asked Questions (FAQs)&lt;/h2&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;What is By.tagName() in Selenium?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;:&amp;nbsp;By.tagName() is an element locator strategy that is used to find web elements by their HTML tag name.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;: When should I use By.tagName()?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;: You can use it when&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;You want to find all elements of a certain type (e.g., all links &amp;lt;a&amp;gt;, all images &amp;lt;img&amp;gt;).&lt;/li&gt;&lt;li&gt;You are working with tables (e.g., rows &amp;lt;tr&amp;gt;, cells &amp;lt;td&amp;gt;).&lt;/li&gt;&lt;li&gt;There’s no unique attribute like ID or Class available.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;Can I use By.tagName() to locate multiple elements?&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;: Yes! You can use findElements(By.tagName(&quot;tagname&quot;)) to retrieve a list of elements.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;What happens if no element is found by tagName()?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;:&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;findElement(By.tagName()) will throw a NoSuchElementException.&lt;/li&gt;&lt;li&gt;findElements(By.tagName()) will return an empty list/collection.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;How is By.tagName() different from other locators like By.id() or By.className()?&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;:&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;By.tagName() will search by the HTML tag and not by the attributes.&lt;/li&gt;&lt;li&gt;It will return many elements, whereas&amp;nbsp;By.id() or By.name() usually return unique elements.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;Is By.tagName() case-sensitive?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;: No. HTML tag names are not case-sensitive, but it is advised to use lowercase (e.g., &quot;div&quot;, &quot;a&quot;).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;What are some common tags I can use with By.tagName()?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;: You can use the following tags:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;a → links&lt;/li&gt;&lt;li&gt;img → images&lt;/li&gt;&lt;li&gt;div → containers&lt;/li&gt;&lt;li&gt;span → inline elements&lt;/li&gt;&lt;li&gt;p → paragraphs&lt;/li&gt;&lt;li&gt;table, tr, td → tables&lt;/li&gt;&lt;li&gt;h1, h2, etc. → headings&lt;/li&gt;&lt;li&gt;input, button → form elements&lt;/li&gt;&lt;/ul&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Common Errors &amp;amp; Troubleshooting&lt;/h2&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Error&lt;/b&gt;:&amp;nbsp;NoSuchElementException&lt;/div&gt;&lt;div&gt;&lt;b&gt;Fix&lt;/b&gt;: It happens when Selenium is unable to find the element by your provided tag name. Make sure the element is available in&amp;nbsp;the DOM and it is visible when Selenium is searching for it.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Error&lt;/b&gt;:&amp;nbsp;Incorrect Tag Name&lt;/div&gt;&lt;div&gt;&lt;b&gt;Fix&lt;/b&gt;: This happens when you use the wrong casing or add typos in the tag name. Always use correct tag name in lower case.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Error&lt;/b&gt;:&amp;nbsp;ElementNotVisibleException / ElementClickInterceptedException&lt;/div&gt;&lt;div&gt;&lt;b&gt;Fix&lt;/b&gt;: This error occurs when an element is not visible or covered by another element. You can use&amp;nbsp;WebDriverWait to make sure it is visible before interaction.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Error&lt;/b&gt;:&amp;nbsp;StaleElementReferenceException&lt;/div&gt;&lt;div&gt;&lt;b&gt;Fix&lt;/b&gt;: This error occurs when Dom is updated. To fix this issue,&amp;nbsp;re-locate the element after DOM update.&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Best&amp;nbsp;Practices&lt;/h2&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Use TagName for Groups: Finding element by tagName is best to find multiple similar elements.&lt;/li&gt;&lt;li&gt;Narrow the Search Scope: To interact with a child element, first locate the parent element&amp;nbsp;and then use tagName inside them to avoid unwanted matches.&lt;/li&gt;&lt;li&gt;Always Use Lowercase Tags: Use tag name in lower case to reduce unwanted errors.&lt;/li&gt;&lt;li&gt;Handle Empty Lists:&amp;nbsp;When using findElements(), check for empty list before performing actions.&lt;/li&gt;&lt;li&gt;Switch to Frames/Windows: If you are working with multiple frames or windows, first of all, switch focus on them before performing any action.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;tagName is a very useful locator in Selenium if used in correct scenarios.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Have any questions or queries? You can ask me in a comment below. I will try my best to answer you.&lt;/p&gt;&lt;/div&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2025/03/tagname-locator-in-selenium.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJSwYSkzor7H6UM0ZEJ6-5RhZBngWWQVhYZM9IRH9ZlxpMYpr5sabX8AT_VQZT3Z8CwyULP3BIzu7En00ms6glW8JbDg7lQB-SixfEVXecIEI0FL4pq9p-Re9yThhd3Im4yEJphLuVkZHElxrne7cYUOmaGyV0jRv00QThPBy5D5DMLcdNBAzQjTaQpnm_/s72-w640-h366-c/find%20tag%20name%20to%20use%20in%20selenium%20test.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-1406385379223665820</guid><pubDate>Sun, 09 Mar 2025 07:02:00 +0000</pubDate><atom:updated>2025-03-09T21:04:58.916-07:00</atom:updated><title>Find Element by Class in Selenium: Complete Guide for Beginners (Best Practices, FAQs)</title><description>&lt;p&gt;&amp;nbsp;Selenium is a flexible automation testing tool that provides&amp;nbsp;multiple ways to locate web elements. findElement(By.className()) is one of the different types of element locators in Selenium. You can use this method in Selenium when an element has a class attribute. It allows you to select a group of elements or a specific element. You can use it to identify web elements like&amp;nbsp;buttons, links, or input fields.&lt;/p&gt;&lt;p&gt;In this guide, we will learn about:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;What findElement(By.className()) is&lt;/li&gt;&lt;li&gt;Why Use Find Element by Class In Selenium?&lt;/li&gt;&lt;li&gt;How to Use findElement(By.className())&lt;/li&gt;&lt;li&gt;Limitations &amp;amp;&amp;nbsp;Advantages&lt;/li&gt;&lt;li&gt;Examples in Java, Python, and C#&lt;/li&gt;&lt;li&gt;Find element by class FAQs&lt;/li&gt;&lt;li&gt;Troubleshooting Common find element by class Errors&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;What is findElement(By.className())?&lt;/h2&gt;&lt;div&gt;className() is a method in the &lt;a href=&quot;https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/By.html&quot; target=&quot;_blank&quot;&gt;By class&lt;/a&gt;. It helps to find elements using their CSS class name.&amp;nbsp;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It returns a &lt;a href=&quot;https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/By.ByClassName.html&quot; target=&quot;_blank&quot;&gt;ByClassName&lt;/a&gt; object, which internally converts the class name into a CSS selector (.classname).&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;This makes it easier for Selenium to locate elements on a webpage using class name.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;In Selenium WebDriver, one can use findElement(By.className()) method to locate an element based on its class name attribute.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If multiple elements have the same class name, then Selenium will return the first matching element by default.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Why Use Find Element by Class In Selenium?&lt;/h2&gt;&lt;div&gt;There are multiple reasons to use find element by class.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Simple and Efficient&lt;/b&gt;:&amp;nbsp;&lt;/h3&gt;&lt;div&gt;Class names are used in HTML to group similar elements like&amp;nbsp;buttons, links, or sections. So it is a straightforward way to find an element by its class.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Common in Web Design&lt;/b&gt;:&amp;nbsp;&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Generally similar elements are styled together using a class name. So you can easily target all those elements using By.className().&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;lt;button class=&quot;submit-button&quot;&amp;gt;Submit&amp;lt;/button&amp;gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;lt;button class=&quot;submit-button&quot;&amp;gt;Cancel&amp;lt;/button&amp;gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;In the above example, both buttons have the same class name&amp;nbsp;submit-button. So you can easily target both of them using&amp;nbsp;findElement(By.className(&quot;submit-button&quot;))&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Readable and Easy to Maintain:&lt;/b&gt;&lt;/h3&gt;&lt;div&gt;If a class name is descriptive like login-button, error-message, or product-card, and you use it in selenium tests, then it will be easy for other developers and testers to read and understand it.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;When Other Selectors Are Less Reliable&lt;/h3&gt;&lt;div&gt;Sometimes other locators like&amp;nbsp;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/find-element-by-id-in-selenium.html&quot; target=&quot;_blank&quot;&gt;By.id()&lt;/a&gt;, &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/name-locator-in-selenium.html&quot; target=&quot;_blank&quot;&gt;By.name()&lt;/a&gt;, or &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/xpath-in-selenium.html&quot; target=&quot;_blank&quot;&gt;By.xpath()&lt;/a&gt; are not working. In that case, using class name locator is more reliable.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Java Syntax&lt;/b&gt;&lt;/h3&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;WebElement element = driver.findElement(By.className(&quot;your-class-name&quot;));&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Python Syntax&lt;/b&gt;&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;element = driver.find_element(By.CLASS_NAME, &quot;your-class-name&quot;)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;C# Syntax&lt;/b&gt;&lt;/h3&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;IWebElement element = driver.FindElement(By.ClassName(&quot;your-class-name&quot;));&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Using class name in XPath&lt;/h2&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;To find an element by class name attribute in Python, you can use XPath as below.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;element = driver.find_element(By.XPATH, &#39;//*[@class=&quot;class_name&quot;]&#39;)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;Here is an example to locate an element by class and ID attributes in Python selenium test script.&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;element = driver.find_element(By.XPATH, &#39;//*[@id=&quot;element_id&quot; and contains(@class, &quot;class_name&quot;)]&#39;)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;To find an element by class and name attribute in Python, you can use XPath as below.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;element = driver.find_element(By.XPATH, &#39;//*[@name=&quot;element_name&quot; and contains(@class, &quot;class_name&quot;)]&#39;)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;You can use the below given XPath syntax in Python to locate an element using class name and text.&lt;/div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;element = driver.find_element(By.XPATH, &#39;//*[contains(@class, &quot;class_name&quot;) and text()=&quot;Exact Text&quot;]&#39;)&lt;/span&gt;&lt;span style=&quot;background-color: transparent; font-family: arial; font-size: 12px;&quot;&gt;T&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;How to Use findElement(By.className())&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;Here is a step-by-step guide to find an element using the class name.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Step 1: Get the class name of an element?&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;To use it, you need the class name of the element before using it in the Selenium test.&lt;/p&gt;&lt;div&gt;To get the class name of web element:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Right click on element.&lt;/li&gt;&lt;li&gt;Select inspect element.&lt;/li&gt;&lt;li&gt;From the inspect element window, you will get a class name as shown in the below image.&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-6Y2rrnelRW8z4mpkoXyGSO2gzGGAdBCfaJEXjoIRlkwwqWzLP2nlUR2I76P72Yv8PgUbuIjOHvmzUFs4R_VTz6ZtGplMUD6T8gnPBqDuf8JfG_bGZdU8rZkM3GbUc13AqBJEZ2o9UZ6dT1LLzggeoT0aYtuCA99zFoWZf8QniXjRQ7JspBA-NKZSuB6l/s820/get%20class%20name%20from%20inspect%20element.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Get class name of web element&quot; border=&quot;0&quot; data-original-height=&quot;440&quot; data-original-width=&quot;820&quot; height=&quot;344&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-6Y2rrnelRW8z4mpkoXyGSO2gzGGAdBCfaJEXjoIRlkwwqWzLP2nlUR2I76P72Yv8PgUbuIjOHvmzUFs4R_VTz6ZtGplMUD6T8gnPBqDuf8JfG_bGZdU8rZkM3GbUc13AqBJEZ2o9UZ6dT1LLzggeoT0aYtuCA99zFoWZf8QniXjRQ7JspBA-NKZSuB6l/w640-h344/get%20class%20name%20from%20inspect%20element.png&quot; title=&quot;Steps to get class name of web element using inspect element.&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Step 2: Get your test page URL&lt;/h3&gt;&lt;div&gt;Copy the URL of the test page you are looking to test in Selenium test.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Step 3: Launch your IDE&lt;/h3&gt;&lt;div&gt;Launch IDE as per your programming language, you use for Selenium Testing, i.e.&amp;nbsp;IDLE,&amp;nbsp;Visual Studio, or Eclipse.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Step 4: Create project and add selenium dependencies&lt;/h3&gt;&lt;div&gt;To run Selenium tests, you need to create a project and add the required Selenium Jars to run Selenium tests in it. Also, you need to update your Chrome browser and &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/02/chrome-driver-download-for-selenium.html&quot; target=&quot;_blank&quot;&gt;download the latest chromedriver&lt;/a&gt;&amp;nbsp;and configure it in your system.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Step 5: Run test&lt;/h3&gt;&lt;div&gt;Here are examples of how to use find element by class in Java, Python, and C# languages.&amp;nbsp;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You need to update test page URLs and class name in the following examples before running the test.&lt;/p&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Java Example&lt;/h3&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class FindByClass {
    public static void main(String[] args) {
        System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;path/to/chromedriver&quot;);
        WebDriver driver = new ChromeDriver();
        driver.get(&quot;https://example.com&quot;);

        WebElement element = driver.findElement(By.className(&quot;example-class&quot;));
        System.out.println(&quot;Element text: &quot; + element.getText());

        driver.quit();
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Python Example&lt;/h3&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;from selenium import webdriver
from selenium.webdriver.common.by import By

# Initialize WebDriver
driver = webdriver.Chrome()
driver.get(&quot;https://example.com&quot;)

# Locate element by class name
element = driver.find_element(By.CLASS_NAME, &quot;example-class&quot;)
print(&quot;Element text:&quot;, element.text)

# Close browser
driver.quit()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3&gt;C# Example&lt;/h3&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;

class FindByClassName
{
    static void Main()
    {
        IWebDriver driver = new ChromeDriver();
        driver.Navigate().GoToUrl(&quot;https://example.com&quot;);

        IWebElement element = driver.FindElement(By.ClassName(&quot;example-class&quot;));
        Console.WriteLine(&quot;Element text: &quot; + element.Text);

        driver.Quit();
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Limitations:&lt;/h2&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Works only with single-class names&lt;/b&gt;: Selenium does not support multiple class names. If the class attribute has multiple class names like&amp;nbsp;&amp;lt;div class=&quot;class1 class2&quot;&amp;gt;.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Returns only the first matching element&lt;/b&gt;:&amp;nbsp;If you are looking to get all elements with the same class, use findElements(By.className()) instead.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Not recommended for dynamically generated class names&lt;/b&gt;: If the class name changes on every page reload, it is recommended to not use it in selenium test scripts.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Advantages:&lt;/h2&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Faster than Other Methods in Some Cases&lt;/b&gt;: Searching by class name will be faster if multiple elements have the same tag but different attributes.&lt;/li&gt;&lt;li&gt;&lt;b&gt;No Need for Complex Selectors&lt;/b&gt;: Unlike other complex selectors like&amp;nbsp;XPath or CSS, find by class name is simple. It&amp;nbsp;does not require extra syntax or logic to identify the element.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Works Well for Elements with Distinct Classes&lt;/b&gt;: This method will directly return the target element, if elements have a clear and unique class name.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Avoids XPath Limitations&lt;/b&gt;: Sometimes&amp;nbsp;XPath struggles with complex queries. Using class name will provide a simpler and more robust solution.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Frequently Asked Questions (FAQs)&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;What is finding element by class name in Selenium?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;:&amp;nbsp;findElement(By.className()) is a Selenium WebDriver method that is&amp;nbsp;used to locate an element using its class name.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;How do I find an element by class name in Selenium?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;: You can use the following syntax&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;driver.find_element(By.CLASS_NAME, &quot;your_class_name&quot;)&lt;/span&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;: What is the difference between findElement(By.className()) and findElements(By.className())?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;:&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;findElement(By.className())&amp;nbsp;returns the first matching class element.&lt;/li&gt;&lt;li&gt;findElements(By.className())&amp;nbsp;returns a list of all matching class elements.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;Can I use multiple class names in findElement(By.className())?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;:&amp;nbsp;No, Selenium does not support compound class names. You can use CSS selector instead like:&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;driver.find_element(By.CSS_SELECTOR, &quot;.classx.classy&quot;)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Question&lt;/b&gt;: Why is find_element_by_class_name deprecated?&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Answer&lt;/b&gt;:&amp;nbsp;Selenium 4 removed find_element_by_class_name. Now, you can use driver.find_element(By.CLASS_NAME, &quot;your_class_name&quot;).&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;How do I click an element found by class name?&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Answer&lt;/b&gt;:&amp;nbsp;After finding the element, use: element.click() in your selenium test.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;How do I get text from an element found by class name?&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Answer&lt;/b&gt;:&amp;nbsp;Use given syntax below to get text:&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;text = driver.find_element(By.CLASS_NAME, &quot;your_class_name&quot;).text&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question:&amp;nbsp;&lt;/b&gt;Can I use findElement(By.className()) for hidden elements?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer:&amp;nbsp;&lt;/b&gt;No, Selenium cannot interact with hidden elements.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;How do I check if an element exists before finding it?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;: You can use the following syntax:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;elements = driver.find_elements(By.CLASS_NAME, &quot;your_class_name&quot;)
if elements:
    print(&quot;Element found!&quot;)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;What’s the best alternative if find element by class name fails?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;:&amp;nbsp;CSS_SELECTOR is the best alternative.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;Can I use regex with find element by class name?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;:&amp;nbsp;No, but you can use XPATH with contains():&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;driver.find_element(By.XPATH, &quot;//*[contains(@class, &#39;partial_class_name&#39;)]&quot;)&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Troubleshooting Common&amp;nbsp;find element by class Errors&lt;/h2&gt;&lt;div&gt;&lt;b&gt;Error&lt;/b&gt;: ❌ NoSuchElementException: Unable to locate element.&lt;/div&gt;&lt;div&gt;&lt;b&gt;Fix&lt;/b&gt;: ✅ You need to check the following things to resolve this error.&lt;/div&gt;&lt;div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Make sure&amp;nbsp;element exists on the page.&lt;/li&gt;&lt;li&gt;Check if the class name is correct (case-sensitive).&lt;/li&gt;&lt;li&gt;Wait for the element to load using WebDriverWait.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;b&gt;Error&lt;/b&gt;: ❌ InvalidSelectorException: Compound class names not permitted.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Fix&lt;/b&gt;: ✅ You will get this error when you try to locate an element using&amp;nbsp;findElement(By.className()) and the element has multiple class names i.e. &amp;lt;div class=&quot;class1 class2&quot;&amp;gt;.&amp;nbsp;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;To fix this error, you can use an alternative element locator like CSS Selector. Example:&amp;nbsp;&lt;/p&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;driver.find_element(By.CSS_SELECTOR, &quot;.class1.class2&quot;)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Error&lt;/b&gt;: ❌ StaleElementReferenceException: Stale element reference&lt;/div&gt;&lt;div&gt;&lt;b&gt;Fix&lt;/b&gt;: ✅ This error occurs when an element is no longer attached to the DOM.&lt;/div&gt;&lt;div&gt;To fix this:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Re-locate the element before interacting with it.&lt;/li&gt;&lt;li&gt;Use WebDriverWait with EC.staleness_of(element).&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;b&gt;Error&lt;/b&gt;: ❌ AttributeError: &#39;WebDriver&#39; object has no attribute &#39;find_element_by_class_name&#39;.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Fix&lt;/b&gt;: ✅ Actually, find_element_by_class_name is deprecated in Selenium 4.&amp;nbsp;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Now in Selenium 4, you can use:&amp;nbsp;&lt;/p&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;driver.find_element(By.CLASS_NAME, &quot;class_name&quot;)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Error&lt;/b&gt;: ❌ ElementClickInterceptedException&lt;/div&gt;&lt;div&gt;&lt;b&gt;Fix&lt;/b&gt;: ✅ This error occurs when another element is blocking the target element.&amp;nbsp;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;To resolve this issue, you can use JavaScriptExecutor to force-click:&lt;/p&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;driver.execute_script(&quot;arguments[0].click();&quot;, element)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Error&lt;/b&gt;: ❌ TimeoutException: element not found within time.&lt;/div&gt;&lt;div&gt;&lt;b&gt;Fix&lt;/b&gt;: ✅ This error occurs when an element is taking time to load.&amp;nbsp;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;To fix this error, use&amp;nbsp;WebDriverWait to wait until it appears:&lt;/p&gt;&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC  

WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, &quot;class_name&quot;)))
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;Error&lt;/b&gt;: ❌ TypeError: find_element_by_class_name() missing 1 required positional argument&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Fix&lt;/b&gt;: ✅ This error occurs when you pass class name incorrectly. Pass the&amp;nbsp;class name correctly:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;driver.find_element(By.CLASS_NAME, &quot;your_class_name&quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Error&lt;/b&gt;: ❌ Multiple elements found when expecting a single element.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Fix&lt;/b&gt;:&amp;nbsp;✅ This error occurs when you use driver.find_element and return multiple elements. In this case, you can use driver.find_elements in Selenium 4.&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;driver.find_elements(By.CLASS_NAME, &quot;your_class_name&quot;)&lt;/span&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Error&lt;/b&gt;: ❌ NoneType object has no attribute &#39;click&#39;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Fix&lt;/b&gt;:&amp;nbsp;✅ Targeted element was not found, so it returned None. In this case, you need to verify the class name or add an explicit wait before interacting with the element.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Error&lt;/b&gt;: ❌ find_element(By.class_name) works in one browser but not another.&lt;/div&gt;&lt;div&gt;&lt;b&gt;Fix&lt;/b&gt;:&amp;nbsp;✅ Different browsers render elements differently. If the find element by class name is not working in a specific browser, then you can try CSS_SELECTOR or XPATH as an alternative.&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Best Practices for Find By Class&lt;/h2&gt;&lt;div&gt;&lt;div&gt;Here are a few important points you need to consider while using&amp;nbsp;Find By Class in Selenium WebDriver automation test.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Prefer selecting elements with unique class names to avoid ambiguity.&lt;/li&gt;&lt;li&gt;Prefer Selenium 4 Syntax (By.CLASS_NAME)&lt;/li&gt;&lt;li&gt;Always use explicit waits to handle dynamic elements.&lt;/li&gt;&lt;li&gt;Use CSS_SELECTOR or XPATH for more reliable selection.&lt;/li&gt;&lt;li&gt;Check for hidden elements before interacting.&lt;/li&gt;&lt;li&gt;Print logs when elements are found or actions are taken for easy debugging.&lt;/li&gt;&lt;li&gt;Make sure that page is fully loaded before interacting with the element.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Pro Tip&lt;/b&gt;:&amp;nbsp;If you often struggle with class selectors, consider using CSS_SELECTOR or XPATH especially for complex DOM structures.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;Now you’re all set to use find by class in Selenium tests without errors!&lt;/div&gt;&lt;p&gt;Have any questions? Drop a comment below! I am ready to help you with.&lt;/p&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2025/03/selenium-find-element-by-class.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-6Y2rrnelRW8z4mpkoXyGSO2gzGGAdBCfaJEXjoIRlkwwqWzLP2nlUR2I76P72Yv8PgUbuIjOHvmzUFs4R_VTz6ZtGplMUD6T8gnPBqDuf8JfG_bGZdU8rZkM3GbUc13AqBJEZ2o9UZ6dT1LLzggeoT0aYtuCA99zFoWZf8QniXjRQ7JspBA-NKZSuB6l/s72-w640-h344-c/get%20class%20name%20from%20inspect%20element.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-8534277234532117095</guid><pubDate>Sun, 09 Mar 2025 04:28:00 +0000</pubDate><atom:updated>2025-03-18T20:13:32.521-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">selenium webdriver</category><title>How to download chromedriver for selenium (Step-by-Step Guide)</title><description>&lt;p&gt;Are you looking to automate tests with Selenium but can’t get the correct version of ChromeDriver? &lt;strong data-end=&quot;780&quot; data-start=&quot;759&quot;&gt;You’re not alone.&lt;/strong&gt;&lt;/p&gt;&lt;p data-end=&quot;968&quot; data-start=&quot;784&quot;&gt;Many testers and developers are struggling with errors like:&lt;br data-end=&quot;825&quot; data-start=&quot;822&quot; /&gt;&lt;/p&gt;&lt;p data-end=&quot;968&quot; data-start=&quot;784&quot;&gt;❌ SessionNotCreatedException: This version of ChromeDriver only supports Chrome version X&lt;/p&gt;&lt;p data-end=&quot;968&quot; data-start=&quot;784&quot;&gt;❌ chromedriver executable needs to be in PATH&lt;/p&gt;&lt;p data-end=&quot;968&quot; data-start=&quot;784&quot;&gt;Here is the solution.&amp;nbsp;&lt;/p&gt;&lt;p data-end=&quot;968&quot; data-start=&quot;784&quot;&gt;This article will teach you how to download, install, and set up ChromeDriver for Selenium in Windows, Linux, and MAC OS (without errors).&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Step 1: Check Your Chrome Version&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;It is necessary to check your Chrome version before downloading&amp;nbsp;chromedriver.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;How to Check Chrome Version&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;div&gt;&lt;span&gt;There are&amp;nbsp;&lt;/span&gt;&lt;span&gt;&lt;b&gt;two methods&lt;/b&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;to check the Chrome browser version.&lt;/span&gt;&lt;/div&gt;&lt;h4&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Method 1:&lt;/span&gt;&lt;/h4&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Open &lt;strong data-end=&quot;1306&quot; data-start=&quot;1289&quot;&gt;Google Chrome.&lt;/strong&gt;&lt;/li&gt;&lt;li&gt;Type &lt;b&gt;chrome://settings/help&lt;/b&gt; in the address bar.&lt;/li&gt;&lt;li&gt;Look for the &lt;b&gt;Version Number&lt;/b&gt; (e.g., My current chrome browser version: &lt;b&gt;134.0.6998.89&lt;/b&gt;)&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvF8VkUFFedI8uMKI-XdYp5TIFzvnTRbIkaGYgAjFgVdb6vXdK2mM08uZNYL1OmOXOlbFQk57gaezM33DceKZw6KXJ7KsyclDs-QS20DPfxntC8uWY-fGbhUWo-XKMWjPwaIbv8BXerb3AELOb8Jlv2H2GNpdr7LciN0vJk3Wn6s2_4Lhfjr-oJdrvVEqx/s923/How%20to%20Check%20Chrome%20Version%20before%20downloading%20chromedriver%20for%20selenium.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Check chrome version for selenium&quot; border=&quot;0&quot; data-original-height=&quot;329&quot; data-original-width=&quot;923&quot; height=&quot;228&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvF8VkUFFedI8uMKI-XdYp5TIFzvnTRbIkaGYgAjFgVdb6vXdK2mM08uZNYL1OmOXOlbFQk57gaezM33DceKZw6KXJ7KsyclDs-QS20DPfxntC8uWY-fGbhUWo-XKMWjPwaIbv8BXerb3AELOb8Jlv2H2GNpdr7LciN0vJk3Wn6s2_4Lhfjr-oJdrvVEqx/w640-h228/How%20to%20Check%20Chrome%20Version%20before%20downloading%20chromedriver%20for%20selenium.png&quot; title=&quot;how to check chrome version before downloading chromedriver for selenium&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;Method 2&lt;/b&gt;:&lt;/p&gt;&lt;p&gt;Click on the three dots at the top-right corner of Chrome browser. It will open the menu.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhil8Lzz1NcdGLkzQHNSkxVLGBtB7xlzTcxSG7NklgDGqgyImjWylB6o70npx5oP_HXjt-_15B6xjZLqJdVObeRrosOP6aFQyCYOR6xs_ct9MBMo352HGVxZGxQ6PvKF2Z3l27ppsbtM-KnxX9p1bFLDjEycy279wZOQ1-nufiLGqFYMRvtY_PrXpIJAw4o/s254/click%20on%20three%20dots%20in%20chrome%20browser.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Click three dots chrome browser&quot; border=&quot;0&quot; data-original-height=&quot;121&quot; data-original-width=&quot;254&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhil8Lzz1NcdGLkzQHNSkxVLGBtB7xlzTcxSG7NklgDGqgyImjWylB6o70npx5oP_HXjt-_15B6xjZLqJdVObeRrosOP6aFQyCYOR6xs_ct9MBMo352HGVxZGxQ6PvKF2Z3l27ppsbtM-KnxX9p1bFLDjEycy279wZOQ1-nufiLGqFYMRvtY_PrXpIJAw4o/s16000/click%20on%20three%20dots%20in%20chrome%20browser.png&quot; title=&quot;click on three dots on chrome browser to open menu&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Select setting from the menu.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjth4eXD2oArJNHv1FlQPE76PO2ZJEmMzolToMYGPGP7OVBosh3renYpcMGK7huyubQF0LNVIjn_ZXBJ0GWtNAd3GahkCvFo1akaN1kUUS0Hkc3-GWjFbkC3VD3vSgvQZ70O7QyoNJQCh2xuC_PmKLSYub8a5iKNriBFeTHJKi5f6HsPQltDdLVyPmC9zh/s296/nevigate%20to%20chrome%20settings.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Select settings&quot; border=&quot;0&quot; data-original-height=&quot;167&quot; data-original-width=&quot;296&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjth4eXD2oArJNHv1FlQPE76PO2ZJEmMzolToMYGPGP7OVBosh3renYpcMGK7huyubQF0LNVIjn_ZXBJ0GWtNAd3GahkCvFo1akaN1kUUS0Hkc3-GWjFbkC3VD3vSgvQZ70O7QyoNJQCh2xuC_PmKLSYub8a5iKNriBFeTHJKi5f6HsPQltDdLVyPmC9zh/s16000/nevigate%20to%20chrome%20settings.png&quot; title=&quot;select settings option from menu to open chrome setting page.&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;It will open the Chrome settings page.&lt;/p&gt;&lt;p&gt;On the settings page, you will find the About Chrome menu at the bottom-left corner.&lt;/p&gt;&lt;p&gt;Click on it.&lt;/p&gt;&lt;p&gt;On the About Chrome page, you can see your Chrome browser&#39;s version as shown in a given image.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyuqfsXNWsuRyB2FMmq2kFJrW5f8OktZrGAXQBQfbbHeAxjpqBHKA95Ah3VZbiY4Zlk84xgy8DOI5kS02_qZpW6uhr6q-EUdCjUqbxFKRDXMgZXrxs9mXbSqK0H-bftaPM40uaYAOXhcloC4-oIk218RXYDlJxp9TflITYzZrWKUvJbzZPJqp3ahUkDcwO/s1071/about%20chrome%20page%20to%20check%20chrome%20version.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;chrome settings page&quot; border=&quot;0&quot; data-original-height=&quot;537&quot; data-original-width=&quot;1071&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyuqfsXNWsuRyB2FMmq2kFJrW5f8OktZrGAXQBQfbbHeAxjpqBHKA95Ah3VZbiY4Zlk84xgy8DOI5kS02_qZpW6uhr6q-EUdCjUqbxFKRDXMgZXrxs9mXbSqK0H-bftaPM40uaYAOXhcloC4-oIk218RXYDlJxp9TflITYzZrWKUvJbzZPJqp3ahUkDcwO/w640-h320/about%20chrome%20page%20to%20check%20chrome%20version.png&quot; title=&quot;view chrome version on settings page.&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Why does this matter?&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Because ChromeDriver must match your Chrome version. If they do not match, you might get an error when executing your Selenium test.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Tips: &lt;/b&gt;Always use the latest version of Google Chrome and a latest stable release version of Chromedriver to minimize errors.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Update on&amp;nbsp;Latest stable version release: Version 134.0.6998.88&lt;/b&gt; of ChromeDriver and Chrome browsers are available to download.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Learn a detailed guide on &lt;b&gt;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/02/what-is-webdriver-in-selenium.html&quot; target=&quot;_blank&quot;&gt;what is WebDriver in Selenium&lt;/a&gt;&lt;/b&gt;.&lt;/p&gt;&lt;div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Step 2: Download the Correct ChromeDriver&lt;/span&gt;&lt;/h2&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Now, let’s download the right version of ChromeDriver.&lt;/p&gt;&lt;p&gt;Find the ChromeDriver version that matches your Chrome browser and OS, and download the right file for your system:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Go to &lt;a href=&quot;https://googlechromelabs.github.io/chrome-for-testing/#stable&quot; target=&quot;_blank&quot;&gt;Official ChromeDriver Download Page&lt;/a&gt;&amp;nbsp;to get direct download link.&lt;/li&gt;&lt;li&gt;Navigate to Stable version section.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKSDr7Jilpvldjy-vWN9qELxn8yOi_RCd4KMNUPZCjYKaNIFZiPduRM3LMBvBgsWCCZkR2QO2HVclmAqP-lyCq3dptDvICfr0VItph5CZ-zpWKPMrxikPn2jm5Q0Pjp9dyOFTUQOHYuela0nl62sFF1ycmiTwY78SHtPMtF411mp82CN1YsxQax3YOpUQc/s1143/Select%20correct%20version%20of%20chromedriver%20as%20per%20your%20OS%20and%20chromedriver.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Download chromedriver from official website&quot; border=&quot;0&quot; data-original-height=&quot;572&quot; data-original-width=&quot;1143&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKSDr7Jilpvldjy-vWN9qELxn8yOi_RCd4KMNUPZCjYKaNIFZiPduRM3LMBvBgsWCCZkR2QO2HVclmAqP-lyCq3dptDvICfr0VItph5CZ-zpWKPMrxikPn2jm5Q0Pjp9dyOFTUQOHYuela0nl62sFF1ycmiTwY78SHtPMtF411mp82CN1YsxQax3YOpUQc/w640-h320/Select%20correct%20version%20of%20chromedriver%20as%20per%20your%20OS%20and%20chromedriver.png&quot; title=&quot;Select correct version of chromedriver based on your OS and chrome browser version.&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;Choose your OS:&lt;/b&gt;&lt;/div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Windows&lt;/b&gt;: chromedriver-win64.zip&lt;/li&gt;&lt;li&gt;&lt;b&gt;Mac (Intel or ARM)&lt;/b&gt;: chromedriver-mac-x64.zip / chromedriver-mac-arm64.zip&lt;/li&gt;&lt;li&gt;&lt;b&gt;Linux&lt;/b&gt;: chromedriver-linux64.zip&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Copy URL from the table as per &lt;b&gt;your OS and Chrome browser&#39;s version&lt;/b&gt; and open it in the browser.&amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpdwQYDxWtpz6usdhdcz6BcVdcYN_W3uyYEbwh4c06vQC_EY05oKfKohYWCw0IQVsRR1CZ8CFjEgld7aBej7ztZtcjNHfsDpkovHTDZoNEgL98EA-2M4jgGZ21K3NV4I2iS6wuwP59TZGczt8VymXWdIxpCC6MxFZ6ui8vGuqqMO_B8iqG1q1wnK6d445-/s800/open%20chromedriver%20download%20url%20in%20browser.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;open chromedriver download url&quot; border=&quot;0&quot; data-original-height=&quot;86&quot; data-original-width=&quot;800&quot; height=&quot;69&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpdwQYDxWtpz6usdhdcz6BcVdcYN_W3uyYEbwh4c06vQC_EY05oKfKohYWCw0IQVsRR1CZ8CFjEgld7aBej7ztZtcjNHfsDpkovHTDZoNEgL98EA-2M4jgGZ21K3NV4I2iS6wuwP59TZGczt8VymXWdIxpCC6MxFZ6ui8vGuqqMO_B8iqG1q1wnK6d445-/w640-h69/open%20chromedriver%20download%20url%20in%20browser.png&quot; title=&quot;open url to download chromedriver&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It will download the Zip file.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwE63_xZ9i8tj2z9Bl3Wati9lpvwYZql1VRrkZKMASq4f1kHFuLEPX9ZbRyGZmne4YzmnJ7LA2O1dpQzY3fHFmEWregKWzQDflmOZ_FiwWbHasPencRowLEMkumEEFuyxBSnIMjoWaUq1WpfB5TOG4uJiIP4KpDHvJO5yue_1n4Szo7Lm1Fg8zeGPWbCN0/s323/chromedriver%20win64%20zip%20file.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;chromedriver win64 zip folder&quot; border=&quot;0&quot; data-original-height=&quot;323&quot; data-original-width=&quot;296&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwE63_xZ9i8tj2z9Bl3Wati9lpvwYZql1VRrkZKMASq4f1kHFuLEPX9ZbRyGZmne4YzmnJ7LA2O1dpQzY3fHFmEWregKWzQDflmOZ_FiwWbHasPencRowLEMkumEEFuyxBSnIMjoWaUq1WpfB5TOG4uJiIP4KpDHvJO5yue_1n4Szo7Lm1Fg8zeGPWbCN0/w293-h320/chromedriver%20win64%20zip%20file.png&quot; title=&quot;downloaded chromedriver zip folder&quot; width=&quot;293&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Once downloaded, extract the ZIP file to get the chromedriver executable.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkAe45DO0bCykVCdgALONt_XhVTXeiv5sY9MdsiJVM40sTD7d2Voo0BykeiNRK-c2J1X-CG5hMHEoAw7sq9hIUeTqNpHf1kftgRK5NqxSGsKF_uFWj-r_VVEnzGlpVKWxyNtJK4aZMEhiI4G_r5M1D9ClPPpr8tHT6Fs9fvB0RLDXCApnq_uiw9loApr_c/s875/unzip%20chromedriver%20folder.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;unzip the zip folder&quot; border=&quot;0&quot; data-original-height=&quot;599&quot; data-original-width=&quot;875&quot; height=&quot;219&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkAe45DO0bCykVCdgALONt_XhVTXeiv5sY9MdsiJVM40sTD7d2Voo0BykeiNRK-c2J1X-CG5hMHEoAw7sq9hIUeTqNpHf1kftgRK5NqxSGsKF_uFWj-r_VVEnzGlpVKWxyNtJK4aZMEhiI4G_r5M1D9ClPPpr8tHT6Fs9fvB0RLDXCApnq_uiw9loApr_c/w320-h219/unzip%20chromedriver%20folder.png&quot; title=&quot;unzip downloaded chromedriver zip folder to extract it&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRZo2h3Vl2nofhuNErnapigQR2CyDrIMFys9GDTciuFSsTmm2Xw35gCbaeBJuAafQ33pTWFTYLfkkGXbL3-KOpaTVu_tM00eUMr2Dt4_Xqgof2yxiZx5ZX_6olzNMO3kgC0JaZyhNSatEpgVFbl_MgIdbtIZxxImH6NfCWgXSVLyxiNl34m_O9Ue3rM3Th/s547/unziped%20chromedriver%20folder%20using%20winzip.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;ChromeDriver unzip&quot; border=&quot;0&quot; data-original-height=&quot;324&quot; data-original-width=&quot;547&quot; height=&quot;190&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRZo2h3Vl2nofhuNErnapigQR2CyDrIMFys9GDTciuFSsTmm2Xw35gCbaeBJuAafQ33pTWFTYLfkkGXbL3-KOpaTVu_tM00eUMr2Dt4_Xqgof2yxiZx5ZX_6olzNMO3kgC0JaZyhNSatEpgVFbl_MgIdbtIZxxImH6NfCWgXSVLyxiNl34m_O9Ue3rM3Th/w320-h190/unziped%20chromedriver%20folder%20using%20winzip.png&quot; title=&quot;extracted folder of chrome driver&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Open extracted folder. You will get the chromedriver.exe (Executable file) file inside it.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhspyRELPllaIu6Jj5Uzc5_79mvLBKlMzvg-24C5NMb1KGDv58NyIG4o05WdLiaCvN5J808QwZY0NRJRYfKPUJhqA-OLFLC0WvTBOb1moJV80KCryGxQz_lcJ63FqUIdfXZQ-5I8ClXFApv_U4A3kZc7cGPsO9D4vnnYYlV9v3zDnpPrUt8ATHE1rpdVhnC/s865/chromedriver%20exe%20file.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;chromedriver exe file&quot; border=&quot;0&quot; data-original-height=&quot;360&quot; data-original-width=&quot;865&quot; height=&quot;133&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhspyRELPllaIu6Jj5Uzc5_79mvLBKlMzvg-24C5NMb1KGDv58NyIG4o05WdLiaCvN5J808QwZY0NRJRYfKPUJhqA-OLFLC0WvTBOb1moJV80KCryGxQz_lcJ63FqUIdfXZQ-5I8ClXFApv_U4A3kZc7cGPsO9D4vnnYYlV9v3zDnpPrUt8ATHE1rpdVhnC/w320-h133/chromedriver%20exe%20file.png&quot; title=&quot;get downloaded chromedriver exe (executable file)&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Tip&lt;/b&gt;: Store chromedriver in a folder from where you can access it easily, like &lt;b&gt;D:/chromedriver/&lt;/b&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Step 3: Install and Set Up ChromeDriver in Selenium&lt;/h2&gt;&lt;p&gt;Now that you have ChromeDriver, but Selenium doesn&#39;t know where it is. You need to tell Selenium where to find it.&lt;/p&gt;&lt;p&gt;There are two options.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Option 1: Set Chromedriver Path in Environment Variable&lt;/h3&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Search for &lt;b&gt;Edit the system environment variables&lt;/b&gt;&amp;nbsp;from Windows search.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Click &lt;/b&gt;on&amp;nbsp;&lt;b&gt;Environment Variable&lt;/b&gt; button from Advanced tab.&lt;/li&gt;&lt;li&gt;Select &lt;b&gt;Path &lt;/b&gt;from &lt;b&gt;System Variables&lt;/b&gt; section and click on &lt;b&gt;Edit &lt;/b&gt;button.&lt;/li&gt;&lt;li&gt;Click on the &lt;b&gt;New &lt;/b&gt;button and set&amp;nbsp;&lt;b&gt;Chromedriver Path&lt;/b&gt; as shown in the image below and click OK.&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;That&#39;s it.&lt;/p&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAg1iuCLRxYdLFiIJztfPSuRq2sS179sRXUEpu4GKyWxDskF-uJDxOPdf0L48tqLm6h2P5cvFKUrgHdjvlem_UyT_c_UHHb4nrqRl3epDsx2mKKcR92JorLuet2cV5MJ6_ovozs_jYfIhPb2oPBHekPQQ2PevhSxQM2oL5dv-nAbtBmXNLRrUK1YU2Cn6j/s1209/Set%20chromdriver%20path%20in%20environment%20variable.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Set chromedriver path&quot; border=&quot;0&quot; data-original-height=&quot;629&quot; data-original-width=&quot;1209&quot; height=&quot;332&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAg1iuCLRxYdLFiIJztfPSuRq2sS179sRXUEpu4GKyWxDskF-uJDxOPdf0L48tqLm6h2P5cvFKUrgHdjvlem_UyT_c_UHHb4nrqRl3epDsx2mKKcR92JorLuet2cV5MJ6_ovozs_jYfIhPb2oPBHekPQQ2PevhSxQM2oL5dv-nAbtBmXNLRrUK1YU2Cn6j/w640-h332/Set%20chromdriver%20path%20in%20environment%20variable.png&quot; title=&quot;Set chromedriver path in environment variable in windows&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Option 2:&amp;nbsp;Specify ChromeDriver Path in Code&lt;/h3&gt;&lt;div&gt;&lt;div&gt;If you don’t want to modify system settings, you can also manually set the path in Selenium code. Here is an example:&lt;/div&gt;&lt;/div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-family: arial; font-size: 12px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: arial; font-size: 12px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;&lt;/span&gt;&lt;/span&gt;&lt;b style=&quot;font-family: arial; font-size: 12px;&quot;&gt;D:\\chromedriver.exe&lt;/b&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&quot;);
	WebDriver driver= new ChromeDriver();		
        driver.get(&quot;https://only-testing-blog.blogspot.com/&quot;);&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;
Note&lt;/b&gt;: Replace &quot;D:\\chromedriver.exe&quot; with the path where you extracted ChromeDriver.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;The Easy Way – Use WebDriver Manager&lt;/h2&gt;&lt;div&gt;&lt;div&gt;It is annoying to download ChromeDriver and all other drivers manually every time the browser version updates. Instead of manually downloading ChromeDriver, let WebDriver Manager handle everything:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here’s a way:&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Install WebDriver Manager in Eclipse&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If you are using Java with Eclipse, you can create a Maven Project and add&amp;nbsp;WebDriver Manager Dependencies in the pom.xml file:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Install&amp;nbsp;&lt;b&gt;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2015/03/how-to-download-and-install-maven-in.html&quot; target=&quot;_blank&quot;&gt;Maven in Eclipse&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;&lt;li&gt;Create a &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2015/03/create-new-maven-project-in-eclipse-for.html&quot; target=&quot;_blank&quot;&gt;&lt;b&gt;Maven project in Eclipse&lt;/b&gt;&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;Get the latest webdrivermanager dependency from&amp;nbsp;&lt;a href=&quot;https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager&quot; target=&quot;_blank&quot;&gt;&lt;b&gt;MVN Repository&lt;/b&gt;&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;Add the webdrivermanager dependency in the pom.xml file.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;Now, you can use WebDriver Manager in your Selenium tests.&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;b&gt;// Automatically download and setup ChromeDriver&lt;/b&gt;
    WebDriverManager.chromedriver().setup();
        
    &lt;b&gt;// Launch Chrome browser&lt;/b&gt;
    WebDriver driver = new ChromeDriver();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;h2&gt;Downloading Older/Previous Versions of ChromeDriver&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Note&lt;/b&gt;: It is not recommended to use older versions of ChromeDriver.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Recently I was looking to download the previous version of ChromeDriver to verify browser compatibility for one of our under development websites.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;I found a &lt;a href=&quot;https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json&quot; target=&quot;_blank&quot;&gt;reliable source to download older versions of ChromeDriver&lt;/a&gt; after 2+ hours of Google search. So I thought, let me share it with all of you guys.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;When you open that page, it contains direct download URLs of ChromeDriver for all previous version releases.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;: If you are looking to download chromedriver&amp;nbsp;131.0.6724.0, you will find a URL like below on that page. You can open it in your browser to start download.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;https://storage.googleapis.com/chrome-for-testing-public/131.0.6724.0/win64/chromedriver-win64.zip&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Similarly, you will find separate ChromeDriver download URLs for all older versions like 128, 129, 130, etc, for Linux, macOS, and Windows.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Common Errors and Fix&lt;/h2&gt;&lt;p&gt;&lt;b&gt;Error&lt;/b&gt;: SessionNotCreatedException – ChromeDriver version mismatch&lt;/p&gt;&lt;p&gt;&lt;b&gt;Fix&lt;/b&gt;: Download the correct ChromeDriver version matching your Chrome browser.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Error&lt;/b&gt;: chromedriver executable needs to be in the PATH&lt;/p&gt;&lt;p&gt;&lt;b&gt;Fix&lt;/b&gt;: Add ChromeDriver to the system PATH or specify its full path in your code.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Error&lt;/b&gt;: selenium.common.exceptions.WebDriverException&lt;/p&gt;&lt;p&gt;&lt;b&gt;Fix&lt;/b&gt;: Update ChromeDriver or use WebDriver Manager.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Frequently Asked Questions (FAQs)&lt;/h2&gt;&lt;div&gt;&lt;b&gt;Question:&lt;/b&gt;&amp;nbsp;Where can I download the latest ChromeDriver?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;: You can download the latest ChromeDriver from the official Google ChromeDriver website: &lt;a href=&quot;https://googlechromelabs.github.io/chrome-for-testing/&quot;&gt;https://googlechromelabs.github.io/chrome-for-testing/&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Question&lt;/b&gt;: How do I check my Chrome version?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;: Go to chrome://settings/help, and your Chrome version will be displayed.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;How do I fix the &quot;ChromeDriver executable needs to be in PATH&quot; error?&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;:&amp;nbsp;Either add ChromeDriver to your system environment variable PATH or specify its full path in your Selenium script.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;What is the easiest way to install ChromeDriver?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;:&amp;nbsp;Use WebDriver Manager.&amp;nbsp;It will automatically download and update ChromeDriver.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;How to fix ChromeDriver version mismatch?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;:&amp;nbsp;The ChromeDriver version mismatch error occurs when a version of ChromeDriver and your Chrome browser do not match. To resolve this ChromeDriver compatibility error, follow these steps.&lt;/div&gt;&lt;div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Check Your Chrome Browser Version&lt;/b&gt;: Go to Chrome browser&#39;s help section and check version. Update version if using older one.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Download the Matching ChromeDriver Version&lt;/b&gt;: Go to the official Chrome driver download page as discussed earlier in this article. Download latest version.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Update ChromeDriver in Your Project&lt;/b&gt;: Update the latest downloaded Chrome driver executable file in your project.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;What should I do if ChromeDriver keeps crashing or does not launch Chrome?&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;: To fix this issue, update your Chrome browser and chromedriver to the latest stable version. Also, check if you are using any browser extension that conflicts with the current version.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;:&amp;nbsp;How do I run ChromeDriver with a specific user profile?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;:&amp;nbsp;Use the --user-data-dir argument in Chrome options.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Question&lt;/b&gt;: How to check installed version of Chrome driver?&lt;/div&gt;&lt;div&gt;&lt;b&gt;Answer&lt;/b&gt;: Steps to check Chrome driver version,&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Open the Command Prompt (Windows) or Terminal (Mac/Linux).&lt;/li&gt;&lt;li&gt;Type command: chromedriver --version.&lt;/li&gt;&lt;li&gt;Press Enter.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;Command prompt will display installed ChromeDriver version number.&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Now you’re all set to run Selenium tests without errors!&lt;/p&gt;&lt;p&gt;Have&amp;nbsp;any issues? Drop a comment below!&lt;/p&gt;&lt;/div&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2025/02/chrome-driver-download-for-selenium.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvF8VkUFFedI8uMKI-XdYp5TIFzvnTRbIkaGYgAjFgVdb6vXdK2mM08uZNYL1OmOXOlbFQk57gaezM33DceKZw6KXJ7KsyclDs-QS20DPfxntC8uWY-fGbhUWo-XKMWjPwaIbv8BXerb3AELOb8Jlv2H2GNpdr7LciN0vJk3Wn6s2_4Lhfjr-oJdrvVEqx/s72-w640-h228-c/How%20to%20Check%20Chrome%20Version%20before%20downloading%20chromedriver%20for%20selenium.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-4353697548430586226</guid><pubDate>Sat, 08 Mar 2025 05:54:00 +0000</pubDate><atom:updated>2025-03-10T06:15:36.782-07:00</atom:updated><title>Name Locator in Selenium: A Complete Guide (Advantages, Limitations, Syntax, Examples, and Alternatives)</title><description>&lt;p&gt;&amp;nbsp;Selenium WebDriver supports many types of element locators like ID, Name, &lt;a href=&quot;http://software-testing-tutorials-automation.com/2025/03/tagname-locator-in-selenium.html&quot; target=&quot;_blank&quot;&gt;TagName&lt;/a&gt;, Class, XPath, and CSS Selectors to find and interact with the web element on a page. One of them is the Name locator. You can use the By.name() method to identify the element using the name attribute of the element. This guide will help you to learn how to use&amp;nbsp;the Name Locator in Selenium, its advantages, limitations, and best practices.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;What is Name Locator in Selenium?&lt;/h2&gt;&lt;div&gt;It is an &lt;a href=&quot;https://www.selenium.dev/documentation/webdriver/elements/locators/&quot; target=&quot;_blank&quot;&gt;element locating strategy&lt;/a&gt; in Selenium WebDriver. It is used&amp;nbsp;to find elements based on the value of their name attribute. If Selenium finds multiple elements with the same name, it will select the first matching element by default.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Syntax&lt;/b&gt;:&amp;nbsp;WebElement element = driver.findElement(By.name(&quot;element_name&quot;));&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Why Use Name Locator?&lt;/h2&gt;&lt;div&gt;There are a couple of advantages and disadvantages of using it in Selenium WebDriver. Let&#39;s look at both of them one by one.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Advantages:&lt;/h3&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Simple and Readable&lt;/b&gt;: It is easy to use in Selenium test script. Also, it helps to improve code readability as a name often describes the function or purpose of the element.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Faster Execution&lt;/b&gt;: Searching an element by Name attribute is faster than XPath element locator.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Works Well in All Major Browsers&lt;/b&gt;: No browser compatibility issues.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Stable&lt;/b&gt;: Generally, it is stable as its value does not change like the ID attribute.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Limitations:&lt;/h3&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Not Unique Always&lt;/b&gt;: There are chances of multiple elements having the same name attribute value. In that case, Selenium will pick the first&amp;nbsp;occurrence.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Dynamic Changes&lt;/b&gt;: If the value of the name attribute changes frequently, Locator will become unreliable.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Limited Coverage&lt;/b&gt;: You may not find the Name attribute for all elements. In such cases, you need to use other locators like &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/find-element-by-id-in-selenium.html&quot; target=&quot;_blank&quot;&gt;find element by ID&lt;/a&gt;, Class, &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/xpath-in-selenium.html&quot; target=&quot;_blank&quot;&gt;write XPath&lt;/a&gt;, or CSS.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Is the Name Locator Faster than Other Element Locators?&lt;/h2&gt;&lt;div&gt;Answer is Yes and No both. It is slower than ID locator, but it is faster than XPath and CSS Selector. Also, it depends on the web page structure. It performs better on the well-structured page.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Why it is Faster Than XPath and CSS Selectors?&lt;/h3&gt;&lt;div&gt;Here are a few reasons why we can say it is faster.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Direct Attribute Access&lt;/b&gt;: It is faster than complex XPath or CSS queries because the Name locator (By.name(&quot;elementName&quot;)) can&amp;nbsp;directly access the element’s name attribute.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Index-Based Searching&lt;/b&gt;: Generally, browsers optimize search for the name attribute. So it is possible to quickly look up a specific attribute instead of&amp;nbsp;traversing the entire DOM.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;When is Name Locator Slower?&lt;/h3&gt;&lt;div&gt;Here are the scenarios when it is slower.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;If multiple elements have the same name attribute,&amp;nbsp;Selenium may have to filter through them. That makes it slower than the ID locator.&lt;/li&gt;&lt;li&gt;If the name attribute is not unique, Selenium will return a list of elements. It requires additional filtering.&lt;/li&gt;&lt;li&gt;In many&amp;nbsp;modern web applications, I have seen that elements are generated dynamically. In such cases, the name attribute may be missing for the element.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;In summary, it is slower than ID locator, but it is faster than&amp;nbsp;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/selenium-find-element-by-class.html&quot; target=&quot;_blank&quot;&gt;className&lt;/a&gt;,&amp;nbsp;CSS Selector, and XPath locators.&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;For better performance, you should use ID locator (If it is present and stable) instead of Name. But if ID is not present, then name selector is a better choice compared to other locators like CSS and XPath.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;How to get the name attribute of an element?&lt;/h2&gt;&lt;div&gt;To get the name attribute of an element, I am using two methods.&lt;/div&gt;&lt;div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Right click on element and select Inspect element option. It will open the HTML structure of the element in a window. You can copy the name attribute from this window.&lt;/li&gt;&lt;li&gt;I am using SelectorsHub element locator. Right click on element, navigate to SelectorsHub option and click Copy Name.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Syntax of Name Locator&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;Syntax in most popular programming languages like Java, Python, and C# is given below.&lt;/div&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Syntax in Java:&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;WebElement element = driver.findElement(By.name(&quot;element_name&quot;));&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Syntax in&amp;nbsp;Python:&lt;/h3&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;element = driver.find_element(By.NAME, &quot;element_name&quot;)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Syntax in&amp;nbsp;C#:&lt;/h3&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;IWebElement element = driver.FindElement(By.Name(&quot;element_name&quot;));&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Examples of How to Use Name Locator in Selenium&lt;/h2&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Now let us look at some real-world and practical examples of&amp;nbsp;using this locator in Selenium.&lt;/p&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Example 1: Locate an Input Field by Name&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;Consider a form with an input field for a user&#39;s name. Here&#39;s how you can identify an input element by name and type value in it.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;HTML Code&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&amp;lt;input type=&quot;text&quot; name=&quot;username&quot; /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Selenium Code (Java):&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;WebElement usernameField = driver.findElement(By.name(&quot;username&quot;));
usernameField.sendKeys(&quot;TestUserName&quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Example 2: Click a Button by Name&lt;/h3&gt;&lt;div&gt;Locate a button using Name locator and click on it.&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;HTML Code:&lt;/b&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&amp;lt;button type=&quot;submit&quot; name=&quot;submitButton&quot;&amp;gt;Submit&amp;lt;/button&amp;gt;&lt;b&gt;
&lt;/b&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;Selenium Code (Python):&lt;/b&gt;&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;submit_button = driver.find_element(By.NAME, &quot;submitButton&quot;)
submit_button.click()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;p&gt;Also, it is possible to write XPath using the name attribute.&lt;/p&gt;&lt;p&gt;Here is an example for the submit button.&lt;/p&gt;&lt;p&gt;//button[@name=&#39;submitButton&#39;]&lt;/p&gt;&lt;/div&gt;&lt;h3&gt;Example 3: Select a Radio Button by Name&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;You can use the Name locator to select a specific option from radio buttons.&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&amp;lt;input type=&quot;radio&quot; name=&quot;gender&quot; value=&quot;male&quot; /&amp;gt; Male
&amp;lt;input type=&quot;radio&quot; name=&quot;gender&quot; value=&quot;female&quot; /&amp;gt; Female
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Selenium Code (C#):&lt;/h3&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;IWebElement maleOption = driver.FindElement(By.Name(&quot;gender&quot;));
maleOption.Click();&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;How to Handle Multiple Elements with Same Name?&lt;/h2&gt;&lt;div&gt;If multiple elements have the same name, and it is only a choice, then you can use the findElements() method and select the element based on index.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here is an example of how to click on the second element when multiple elements are found with the same name attributes.&lt;/p&gt;&lt;div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;List&amp;lt;WebElement&amp;gt; radioButtons = driver.findElements(By.name(&quot;age&quot;));
radioButtons.get(1).click(); // Clicks the second radio button
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Best Practices&lt;/h2&gt;&lt;div&gt;You should follow these guidelines when using the Name selector.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Ensure Uniqueness&lt;/b&gt;: Make sure the Name attribute you are using is unique on the page.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Combine with Other Locators&lt;/b&gt;: To make it robust and if it is necessary, combine it with other locators like&amp;nbsp;CSS Selectors or XPath.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Avoid Hardcoding&lt;/b&gt;: If the value of Name is changing frequently, it is advisable to use a dynamic strategy.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Don’t Rely Exclusively on Name&lt;/b&gt;: In some cases, the ID or class attribute might be better for more accuracy.&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Alternative Locators in Selenium&lt;/h2&gt;&lt;div&gt;If you find&amp;nbsp;Name Locator isn&#39;t reliable, you can consider using the following locators instead.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;ID Locator&lt;/b&gt; – By.id(&quot;element_id&quot;)&lt;/li&gt;&lt;li&gt;&lt;b&gt;Class Name Locator&lt;/b&gt; – By.className(&quot;class_name&quot;)&lt;/li&gt;&lt;li&gt;&lt;b&gt;CSS Selector&lt;/b&gt; – By.cssSelector(&quot;css_expression&quot;)&lt;/li&gt;&lt;li&gt;&lt;b&gt;XPath &lt;/b&gt;– By.xpath(&quot;xpath_expression&quot;)&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;Name is one of the powerful element locators in Selenium, especially when dealing with forms and input elements. It is simple, stable, and easy to use in Selenium test scripts. However, like other locators, it has some limitations and disadvantages. If you have proper knowledge of when to and how to use it, you can write better automation tests using it. No matter if you are&amp;nbsp;new to Selenium or a seasoned professional.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2025/03/name-locator-in-selenium.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-6835720116757617014</guid><pubDate>Fri, 07 Mar 2025 11:58:00 +0000</pubDate><atom:updated>2025-03-11T04:17:01.578-07:00</atom:updated><title>Find Element by ID in Selenium: A Complete Guide with Examples</title><description>&lt;p&gt;Locating element is a crucial part in Selenium automation testing. There are many element locators available in Selenium, but finding an element by ID is one of the most reliable and most expert-recommended methods.&lt;/p&gt;&lt;h2 data-pm-slice=&quot;1 1 []&quot;&gt;Why Use ID to Locate Elements?&lt;/h2&gt;&lt;div&gt;There are many different element locators available in Selenium. But why should you prefer ID? Here are reasons.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Unique Identifier&lt;/b&gt;: Generally, ID is unique on the page. That makes it most reliable to use it in the Selenium test scripts.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Faster Execution&lt;/b&gt;: It is the quickest and fastest way to find an element from the page compared to other locators like&amp;nbsp;XPath or CSS selectors.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Improved Stability&lt;/b&gt;: There are fewer chances of changing ID in the future. It will reduce your maintenance effort&amp;nbsp;in test scripts.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Supported in All Browsers&lt;/b&gt;: Works well in all major browsers without any compatibility issues.&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;Now let us see why ID is faster than other element locators.&lt;/div&gt;&lt;/div&gt;&lt;span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Why is finding an element by ID the fastest&amp;nbsp;element locator strategy?&lt;/h2&gt;&lt;p&gt;There are multiple reasons as below.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Direct Mapping in the DOM&lt;/b&gt;: &lt;a href=&quot;https://www.selenium.dev/documentation/webdriver/elements/finders/&quot; target=&quot;_blank&quot;&gt;Finding an element by ID&lt;/a&gt; is the fastest element locator strategy because browsers have an optimized lookup mechanism to find elements by ID instantly.&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;b&gt;Optimized Browser API&lt;/b&gt;: Also, Selenium is using&amp;nbsp;browser&#39;s native getElementById() method, which is highly optimized for performance.&lt;/li&gt;&lt;li&gt;&lt;b&gt;No Complex Query Processing&lt;/b&gt;: No need to search in the entire DOM tree like XPath locator and CSS selectors.&amp;nbsp;findElement(By.id()) retrieves the element in constant time.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Minimal Resource Consumption&lt;/b&gt;:&amp;nbsp;Since IDs are unique, the search stops as soon as the element is found.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;Always prefer to use ID as an element locator if an element has a unique ID.&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;How to Find ID of element from web page?&lt;/h2&gt;&lt;div&gt;You need actual ID of the element to use it in the Selenium test script. There are multiple ways to find the ID of the element. But you can use any of the following ways that I am using to get an element&#39;s ID easily.&lt;/div&gt;&lt;div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Using Inspect Element&lt;/b&gt;: Right click on Element -&amp;gt; Select Inspect. In the inspect element window, you will get the ID of the element.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Using SelectorsHub Plugin&lt;/b&gt;: Install SelectorsHub extension -&amp;gt; Right click on element -&amp;gt; Navigate to SelectorsHub -&amp;gt; and Select Copy ID. It will copy the ID of the element.&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Syntax to Find Element by ID in Selenium&lt;/h2&gt;&lt;div&gt;Here are examples to find an element by ID in Selenium Python, Java, and C#. Well, there is no language dependency in finding an element by ID. But for better understanding, I have provided an example in all the popular three languages used with Selenium WebDriver.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Python Example to Find Element by ID&lt;/h3&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;from selenium import webdriver
from selenium.webdriver.common.by import By

# Initialize WebDriver
driver = webdriver.Chrome()

# Open a webpage
driver.get(&quot;https://example.com&quot;)

# Find element by ID
element = driver.find_element(By.ID, &quot;id_of_element&quot;)

# Perform action
element.click()

# Close the browser
driver.quit()&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Java&amp;nbsp;Example to Find Element by ID&lt;/h3&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class FindByIdExample {
    public static void main(String[] args) {
        // Set up WebDriver
        WebDriver driver = new ChromeDriver();
        
        // Open webpage
        driver.get(&quot;https://example.com&quot;);
        
        // Find element by ID
        WebElement element = driver.findElement(By.id(&quot;id_of_element&quot;));
        
        // Perform action
        element.click();
        
        // Close browser
        driver.quit();
    }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;C#&amp;nbsp;Example to Find Element by ID&lt;/h4&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;from selenium import webdriver
from selenium.webdriver.common.by import By

# Initialize WebDriver
driver = webdriver.Chrome()

# Open a webpage
driver.get(&quot;https://example.com&quot;)

# Find element by ID
element = driver.find_element(By.ID, &quot;id_of_element&quot;)

# Perform action
element.click()

# Close the browser
driver.quit()&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Handling NoSuchElementException&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;For best practices, it is essential to handle&amp;nbsp;NoSuchElementException if Selenium is unable to find an element located by ID. You can include a try catch block as provided in the following examples.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Handling NoSuchElementException in Python&lt;/h4&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;from selenium.common.exceptions import NoSuchElementException

try:
    element = driver.find_element(By.ID, &quot;wrong_id_of_element&quot;)
except NoSuchElementException:
    print(&quot;Element not found!&quot;)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Handling NoSuchElementException in Java&lt;/h4&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;import org.openqa.selenium.NoSuchElementException;

try {
    WebElement element = driver.findElement(By.id(&quot;wrong_id_of_element&quot;));
} catch (NoSuchElementException e) {
    System.out.println(&quot;Element not found!&quot;);
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Handling NoSuchElementException in C#&lt;/h4&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;using OpenQA.Selenium;
using OpenQA.Selenium.NoSuchElementException;

try
{
    IWebElement element = driver.FindElement(By.Id(&quot;wrong_id_of_element&quot;));
}
catch (NoSuchElementException)
{
    Console.WriteLine(&quot;Element not found!&quot;);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Also, you can use an element&#39;s ID in XPath like //input[@id=&#39;FName&#39;] to find an element by attribute ID in XPath with Selenium.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;This way, you can handle&amp;nbsp;NoSuchElementException in Selenium WebDriver if it is unable to find an element by ID.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Alternatives of Find Element By ID&lt;/h2&gt;&lt;div&gt;Find element by ID is the best choice if the element has a unique and stable ID. But it is possible that the element you are trying to locate does not have an ID attribute. In this case, you can consider using other attributes like&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://software-testing-tutorials-automation.com/2025/03/tagname-locator-in-selenium.html&quot; target=&quot;_blank&quot;&gt;Tag Name (By.TAG_NAME)&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/name-locator-in-selenium.html&quot; target=&quot;_blank&quot;&gt;Name (By.NAME)&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/selenium-find-element-by-class.html&quot; target=&quot;_blank&quot;&gt;Class Name (By.CLASS_NAME)&lt;/a&gt;&lt;/li&gt;&lt;li&gt;CSS Selector (By.CSS_SELECTOR)&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/xpath-in-selenium.html&quot; target=&quot;_blank&quot;&gt;XPath (By.XPATH)&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;If your element contains a link (text inside &amp;lt;a&amp;gt; elements), then you can use&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/linktext-selenium.html&quot; target=&quot;_blank&quot;&gt;Link Text (By.LINK_TEXT)&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Partial Link Text (By.PARTIAL_LINK_TEXT)&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Using Explicit Waits for Better Stability&lt;/h2&gt;&lt;div&gt;If the element or page is taking a longer time to load, then it is recommended to use explicit wait to reduce unnecessary errors.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here is an example of an explicit wait&lt;/p&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Wait until the element is present
element = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.ID, &quot;element_id&quot;))
)
element.click()
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;div&gt;It will explicitly wait for 10 seconds if unable to locate the element by ID while you run the Selenium test.&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Common Errors and Troubleshooting Tips&lt;/h2&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;ElementNotVisibleException&lt;/b&gt;: That means, the element is present on the page but not visible to Selenium. You can try using&amp;nbsp;explicit waits.&lt;/li&gt;&lt;li&gt;&lt;b&gt;StaleElementReferenceException&lt;/b&gt;: This exception occurs when an element is no longer valid. You can retry to locate it again.&lt;/li&gt;&lt;li&gt;&lt;b&gt;InvalidSelectorException&lt;/b&gt;:&amp;nbsp;Check if the selector syntax is incorrect.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Best Practices&lt;/h2&gt;&lt;div&gt;&lt;div&gt;For best practices, you must consider these points while using find element by ID.&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Make sure the&amp;nbsp;&lt;b&gt;ID is unique&lt;/b&gt;&amp;nbsp;on the page. It will help to avoid wrong element selection.&lt;/li&gt;&lt;li&gt;Do not hesitate to&amp;nbsp;&lt;b&gt;use&amp;nbsp;explicit waits&lt;/b&gt;&amp;nbsp;if elements take time to load.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Use logging&amp;nbsp;&lt;/b&gt;to debug test failures effectively.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Avoid using&amp;nbsp;dynamically changing IDs&lt;/b&gt;&amp;nbsp;in the test script. Such IDs can break the test scripts.&amp;nbsp;&lt;/li&gt;&lt;li&gt;If the element&#39;s ID is changing dynamically, and ID is the only choice, then you can use ID in XPath with&amp;nbsp;contains(),&amp;nbsp;starts-with(), or ends-with() functions. It will help you to match partial attribute value. You can refer to this&amp;nbsp;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/xpath-in-selenium.html&quot; target=&quot;_blank&quot;&gt;XPath in Selenium&lt;/a&gt;&amp;nbsp;tutorial where I mentioned how to handle dynamic changing ID in XPath.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;Using find element by ID is one of the best, convenient, and&amp;nbsp;efficient element locator strategies. It is fast, reliable, and easy to use. By following these best practices,&amp;nbsp;you can improve the stability of your test automation.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Still have any questions? You can ask me in the comment.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2025/03/find-element-by-id-in-selenium.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-3592989921376593858</guid><pubDate>Fri, 07 Mar 2025 05:10:00 +0000</pubDate><atom:updated>2025-03-11T22:15:05.771-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">xpath in selenium</category><title>How to write and Use XPath in Selenium (Using attributes, Axes, operators, functions)</title><description>&lt;p&gt;One of the main reasons behind Selenium&#39;s popularity is that it supports multiple element locators. And one of them is XPath. XPath is one of the most powerful and flexible element locators in Selenium Webdriver. It helps you to navigate through the&amp;nbsp;HTML structures of a page to locate an element using XPath.&lt;/p&gt;&lt;p&gt;In this guide, we will learn about &lt;a href=&quot;https://www.w3schools.com/xml/xpath_intro.asp&quot; target=&quot;_blank&quot;&gt;what is XPath&lt;/a&gt;, how it works, and when to use it in Selenium test scripts. It is necessary to learn about different ways to find XPath of the element and how to write XPath syntax easily using real world examples. By the end, you will know the difference between&amp;nbsp;absolute vs. relative XPath,&amp;nbsp;common XPath expressions, and how to handle&amp;nbsp;dynamic and&amp;nbsp;nested elements like a pro.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR0yeaDh7K6QA4I6cKZ-cYz5LSYT8cA72cZy27UCG7QJ_D08bnvOCZKJbAB_TCVmFeV4JaMu8MVbZWp10B3g-cRC3165SgLnDKqNi-JrDYNup7bn77yS2Uhiqu0BCuT71I6h5GnxpmQ4nNLODka2mMs9UUVSJWRMLtoKeqM6U0ypHRxjTLXrzmib20BL7y/s817/How%20to%20find%20XPath%20in%20Selenium.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;How to find XPath in Selenium&quot; border=&quot;0&quot; data-original-height=&quot;426&quot; data-original-width=&quot;817&quot; height=&quot;209&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR0yeaDh7K6QA4I6cKZ-cYz5LSYT8cA72cZy27UCG7QJ_D08bnvOCZKJbAB_TCVmFeV4JaMu8MVbZWp10B3g-cRC3165SgLnDKqNi-JrDYNup7bn77yS2Uhiqu0BCuT71I6h5GnxpmQ4nNLODka2mMs9UUVSJWRMLtoKeqM6U0ypHRxjTLXrzmib20BL7y/w400-h209/How%20to%20find%20XPath%20in%20Selenium.png&quot; title=&quot;Find xpath using attributes, Axes, operator and how to build customized XPath to use in selenium java, C# and python test scripts.&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;What is XPath in Selenium?&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Just like you use GPS to locate your car, XPath(XML Path Language) is used to locate an element on a webpage. It helps Selenium WebDriver testers to&amp;nbsp;navigate through a webpage’s structure to find&amp;nbsp;the exact element they need. No matter in which language you are working, the Same XPath will work in Java, Python, C#, and JavaScript languages.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;When to use XPath In Selenium WebDriver?&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Just recently, one of my colleagues was trying to locate an element by ID, but it was changing on page reloads. Then he tried to locate it by class name, but there was no unique class name of the element. Also, there was no option to locate element by name, &lt;a href=&quot;http://software-testing-tutorials-automation.com/2025/03/tagname-locator-in-selenium.html&quot; target=&quot;_blank&quot;&gt;tag name&lt;/a&gt;, etc. In such a scenario, the only way to locate the element is by XPath.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV-FOeiwAk6p0DEMfLYczSpPSayOPh0MpVs7mu09WBuv_9O_mPj9bhRyhaAHqpyV6X8SjX4T9KgQt-Cg03o511afyuUY0bxjJZVn64U6wwrjtKLx0HE1WKqHRJlhQ4MPRM-r0ytPY2ls42dSCMlNAJ6Z63igK9aRl7XJ8GPB2vhbtepz6ym8I4T0h3dOzN/s524/when%20to%20use%20xpath.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;when to use xpath in selenium&quot; border=&quot;0&quot; data-original-height=&quot;180&quot; data-original-width=&quot;524&quot; height=&quot;138&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV-FOeiwAk6p0DEMfLYczSpPSayOPh0MpVs7mu09WBuv_9O_mPj9bhRyhaAHqpyV6X8SjX4T9KgQt-Cg03o511afyuUY0bxjJZVn64U6wwrjtKLx0HE1WKqHRJlhQ4MPRM-r0ytPY2ls42dSCMlNAJ6Z63igK9aRl7XJ8GPB2vhbtepz6ym8I4T0h3dOzN/w400-h138/when%20to%20use%20xpath.png&quot; title=&quot;You can use xpath when other locators are not working and dealing with complex html structure.&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can use XPath element locator:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;When dealing with dynamic elements that change frequently.&lt;/li&gt;&lt;li&gt;When you need to navigate between elements (like finding a button inside a specific div).&lt;/li&gt;&lt;li&gt;When other locators don’t work or aren’t stable.&lt;/li&gt;&lt;li&gt;When working with complex web structures like SVG or Shadow DOM.&lt;/li&gt;&lt;/ul&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;When not to use XPath in Selenium?&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;While XPath is a powerful locator, it’s not always the best choice.&amp;nbsp;Here are some situations where you should avoid using XPath and opt for better alternatives.&lt;/p&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;When performance is important → XPath is the slowest option.&lt;/li&gt;&lt;li&gt;When an element has a unique and stable ID or Name. → Use By.id() to By.name().&lt;/li&gt;&lt;li&gt;When CSS Selectors can do the job → Use By.cssSelector()&lt;/li&gt;&lt;li&gt;When dealing with Shadow DOM → It is better to use JavaScript instead of XPath.&lt;/li&gt;&lt;li&gt;When working with SVG Elements → CSS Selectors is a better option.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Why Should You Use XPath?&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If you are working with Selenium WebDriver automation, you have definitely heard about XPath. But do you know why to use XPath over other element locators like&amp;nbsp;ID, Name, or CSS Selectors? Let us break it down in simple words.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;XPath Can Find Any Element on the Page&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Think of XPath as a GPS for your web page. It can find an element even if it is&amp;nbsp;buried in the DOM (Document Object Model). When other locators fail, XPath will work perfectly in your test.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Great for Dynamic and Complex Elements&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;In modern websites, you might have seen that elements are generated on the fly. Meaning their IDs or classes change constantly. To locate such elements, you can build an XPath&amp;nbsp;using flexible expressions instead of relying on static attributes.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;You Can Move Around the DOM Like a Pro&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Using XPath, one can navigate&amp;nbsp;between elements. It is easy to&amp;nbsp;find a parent, child, or sibling element. When elements do not have&amp;nbsp;unique attributes, this is a super handy way to locate an element by&amp;nbsp;referencing another nearby element.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Absolute vs. Relative XPath&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Absolute XPath&lt;/b&gt; (/html/body/div/input) is like providing a full direction from the beginning of the page.&amp;nbsp;It is precise, but fragile (one small change can break your XPath).&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4N5RvV72RsOStbnJepz1Rs6XuVmnkivM8aOfJ4_4ziMVu8MJ1JZqoeSM6CafJ3AbsOjS-5LCBg5G3aKNFLRwh6kVfIPJ3jPAKTYvfV3unCPsdb8fVI2ylxpiehq4LYN7QQafxF2m5Da0DjGoPCFJdHrNSIE5acfvFF92J6mj7NdXTfLwAn6OhgpQOJ2s2/s820/absolute%20xpath%20of%20google%20search%20box.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Absolute XPath&quot; border=&quot;0&quot; data-original-height=&quot;462&quot; data-original-width=&quot;820&quot; height=&quot;225&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4N5RvV72RsOStbnJepz1Rs6XuVmnkivM8aOfJ4_4ziMVu8MJ1JZqoeSM6CafJ3AbsOjS-5LCBg5G3aKNFLRwh6kVfIPJ3jPAKTYvfV3unCPsdb8fVI2ylxpiehq4LYN7QQafxF2m5Da0DjGoPCFJdHrNSIE5acfvFF92J6mj7NdXTfLwAn6OhgpQOJ2s2/w400-h225/absolute%20xpath%20of%20google%20search%20box.png&quot; title=&quot;Absolute XPath example of google search box&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Relative XPath&lt;/b&gt; (//input[@type=&#39;text&#39;]) is a more flexible way to locate an element&amp;nbsp;based on its attributes, no matter where they are on the page.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOeu81u6VQDdd_Bjnd3YvkUGUjeWFs9w-_pB5d1K8pUE_j123vU7K4wKfyG8CqD3dOkzw5aA8Lp-m3qa932PfqmnPjFhzeSseM0hNAZHYo5oB56irz_H6hxQ40ekJfRURiiPT-kgWjZ2CfX3rlYo0bWMq59c_ytolwgb8fqKLO5psKmS5nNBXzUXtQAoCg/s824/relative%20xpath%20of%20google%20search%20box.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Relative XPath&quot; border=&quot;0&quot; data-original-height=&quot;450&quot; data-original-width=&quot;824&quot; height=&quot;219&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOeu81u6VQDdd_Bjnd3YvkUGUjeWFs9w-_pB5d1K8pUE_j123vU7K4wKfyG8CqD3dOkzw5aA8Lp-m3qa932PfqmnPjFhzeSseM0hNAZHYo5oB56irz_H6hxQ40ekJfRURiiPT-kgWjZ2CfX3rlYo0bWMq59c_ytolwgb8fqKLO5psKmS5nNBXzUXtQAoCg/w400-h219/relative%20xpath%20of%20google%20search%20box.png&quot; title=&quot;Relative xpath of google search box&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Powerful Search Functions&lt;/h3&gt;&lt;div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;XPath has built-in search functions like contains(), starts-with(), and text(). It makes it easier to find an element on the web page.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;contains(): //button[contains(text(),&#39;Submit&#39;)]&lt;/b&gt;: Finds buttons with &quot;Submit&quot; in the text.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAqy4PaF9RNEXq8yj6d9qk8PAks4NWmJciNA3ENKhmWpoZavGUQy2NHipjB1MvqZ-Chpd3tbvyATeMJWpw-u-0T2_K8aDucKPuW4A2QNGcncio1LV8HXiCj5IK6wAwzBoG4qd5L7spNJiXPY9s47bSnBr94FIrDIDIEnBWLEt66hJ5KBO-jJklsFQwYSsI/s213/xpath%20with%20contains%20method.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;159&quot; data-original-width=&quot;213&quot; height=&quot;159&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAqy4PaF9RNEXq8yj6d9qk8PAks4NWmJciNA3ENKhmWpoZavGUQy2NHipjB1MvqZ-Chpd3tbvyATeMJWpw-u-0T2_K8aDucKPuW4A2QNGcncio1LV8HXiCj5IK6wAwzBoG4qd5L7spNJiXPY9s47bSnBr94FIrDIDIEnBWLEt66hJ5KBO-jJklsFQwYSsI/s1600/xpath%20with%20contains%20method.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;starts-with():&amp;nbsp;//button[starts-with(@class,&#39;drop&#39;)]&lt;/b&gt;: Finds input textbox elements where the class value starts with &quot;drop&quot; text.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEjlt9Pf204EFwgRr7TiLBhBhrP193RkgHlATuC69mIz-6JyePz7LNRxaql7DFpoHGikScAWak-YEP93WRhCa-Wgqp43e1vqsjEVyHWzAHCgjoCDsDgLzZir6dbd8m6CxAtAtXfD2aH1lXgtZ9zU2fpYTEfs1ANZYXJ1X2X9lehE3TsAg87AJxzwqpe3nx/s478/xpath%20using%20starts-with%20method.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;starts-with in xpath&quot; border=&quot;0&quot; data-original-height=&quot;261&quot; data-original-width=&quot;478&quot; height=&quot;175&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEjlt9Pf204EFwgRr7TiLBhBhrP193RkgHlATuC69mIz-6JyePz7LNRxaql7DFpoHGikScAWak-YEP93WRhCa-Wgqp43e1vqsjEVyHWzAHCgjoCDsDgLzZir6dbd8m6CxAtAtXfD2aH1lXgtZ9zU2fpYTEfs1ANZYXJ1X2X9lehE3TsAg87AJxzwqpe3nx/w320-h175/xpath%20using%20starts-with%20method.png&quot; title=&quot;xpath using the starts-with function&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;text(): //h1[text()=&#39;Hello&#39;]&lt;/b&gt;: Finds an element with exact text &quot;Hello&quot;.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Handles Shadow DOM &amp;amp; SVG Elements&lt;/h3&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It is hard or impossible to locate&amp;nbsp;elements like SVG graphics or Shadow DOM elements using other element locators. But you can access such elements easily using XPath.&lt;/p&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Combine Multiple Conditions for Precision&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Are you looking to&amp;nbsp;find a specific input field?&amp;nbsp;You can combine conditions like this to find an element using multiple conditions. Example:&amp;nbsp;//input[@type=&#39;text&#39; and @name=&#39;username&#39;].&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;What are the different types of XPath?&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Mainly there are two types of XPath that you can use in Selenium.&amp;nbsp;Absolute XPath and Relative XPath.&amp;nbsp;Each type has its own use case, advantages, and limitations. As experts suggest, Relative XPath is more reliable than the Absolute XPath.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Let’s go through them step by step to learn how to build XPath with examples.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Absolute XPath (Avoid If Possible!)&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Absolute XPath Provides exact path from the root &amp;lt;html&amp;gt; tag to your element. But it can break if page structure changes.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It is just like giving a direction to someone like&amp;nbsp;&quot;Go to the first building, enter the second room, then open the first drawer.&quot;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example of Absolute XPath&lt;/b&gt;:&lt;/p&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 660.328px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;/html/body/div[1]/form/input&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It will locate the input element which is present on the given full path.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Pros and Cons of&amp;nbsp;Absolute XPath&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Pros of Absolute XPath:&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Precise:&lt;/b&gt;&amp;nbsp;Points directly to your targeted element.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Easy to generate&lt;/b&gt;: You can easily copy it from your browser&#39;s dev tool.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Cons of Absolute XPath&lt;/b&gt;:&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Easily breaks&lt;/b&gt;: It can break even if there is a small change in page structure.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Hard to maintain&lt;/b&gt;: You need to update the XPath even a small update on the page.&lt;/li&gt;&lt;li&gt;&lt;b&gt;When to use?&lt;/b&gt;: Only as a last resort when nothing else works.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Relative XPath (The Smart Choice!)&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Relative XPath can find an element from&amp;nbsp;anywhere in the DOM. It does not follow the strict path, but&amp;nbsp;looks for the element based on its properties.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example of Relative XPath&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 660.328px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;//input[@id=&#39;username&#39;]&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It will locate the &amp;lt;input&amp;gt; field with the ID username from anywhere on the page.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Pros of&amp;nbsp;Relative XPath&lt;/h4&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;More flexible:&lt;/b&gt; It works&amp;nbsp;even if the structure of the page changes.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Easier to maintain:&lt;/b&gt;&amp;nbsp;Doesn’t break with minor updates.&lt;/li&gt;&lt;li&gt;&lt;b&gt;More readable&lt;/b&gt;: You can locate elements by attributes, text, or relationships.&lt;/li&gt;&lt;li&gt;&lt;b&gt;When to use?:&lt;/b&gt; Always prefer relative XPath over Absolute XPath. It is the recommended method for XPath.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;All Possible Ways to Write XPath in Selenium&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Now let us see how you can write XPath of an element using different&amp;nbsp;Attributes and functions.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;We will use the below given sample login form for&amp;nbsp;demonstration.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Login Page&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div class=&quot;container&quot;&amp;gt;
        &amp;lt;form id=&quot;loginForm&quot;&amp;gt;
            &amp;lt;label for=&quot;username&quot;&amp;gt;Username:&amp;lt;/label&amp;gt;
            &amp;lt;input type=&quot;text&quot; class=&quot;input-field&quot; id=&quot;uname&quot; name=&quot;username&quot; placeholder=&quot;Enter username&quot;&amp;gt;

            &amp;lt;label for=&quot;password&quot;&amp;gt;Password:&amp;lt;/label&amp;gt;
            &amp;lt;input type=&quot;password&quot; id=&quot;pass&quot; name=&quot;password&quot; placeholder=&quot;Enter password&quot;&amp;gt;

            &amp;lt;button type=&quot;submit&quot;&amp;gt;Login&amp;lt;/button&amp;gt;
        &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;1. XPath Using Different Attributes&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can locate elements using different attributes like&amp;nbsp;id, name, class, and type.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here are examples of building XPath using&amp;nbsp;id, name, class, and type attributes.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Using ID attribute&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If an element has an ID attribute, then you can use it to build XPath as below.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;//input[@id=&#39;uname&#39;]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;This XPath will locate an element with attribute id=uname.&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Using Name attribute&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;If an element does not have an ID but a name attribute is available, then you can utilize it to generate XPath. Here is an Example:&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;//input[@name=&#39;username&#39;]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;This XPath will locate an element with attribute name=username.&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Using Class attribute&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Same as ID and Name attributes, you can use the class attribute as well.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;//input[@class=&#39;input-field&#39;]
&lt;/code&gt;&lt;/pre&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;This&lt;/span&gt;&lt;/code&gt;&amp;nbsp;XPath will locate an element with attribute class=input-field.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Using Type attribute&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can use&amp;nbsp;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;//input[@type=&#39;password&#39;]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;This&amp;nbsp;&lt;/span&gt;&lt;/code&gt;XPath will locate an element with attribute type=password.&lt;/p&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;2. XPath&amp;nbsp;Using contains() Function&lt;/h3&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can use the contains function in XPath as below when the element has a dynamic attribute value.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;//input[contains(@name, &#39;user&#39;)]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;It will find any input field where the name contains text &quot;user&quot; (e.g., user123, user_login).&lt;/code&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;//button[contains(text(), &#39;Login&#39;)]&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It will find&amp;nbsp;a button that contains the text &quot;Login&quot; in its text.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;3. XPath Using&amp;nbsp;starts-with() Function&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can use the starts-with() function when an element’s attribute starts with a fixed text pattern.&lt;/p&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;//input[starts-with(@name, &#39;user&#39;)]&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;It will locate elements with name=&quot;username&quot;, name=&quot;user123&quot;, etc.&lt;/code&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;4. XPath using&amp;nbsp;text() Function&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can use the text() function to find elements by their exact text value.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;//button[text()=&#39;Login&#39;]&lt;/pre&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It will find a button with&amp;nbsp;exact text &quot;Login&quot;.&lt;/p&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;5.&amp;nbsp;XPath Using Logical Operators (and, or)&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can use multiple conditions to narrow down your selection.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;//input[@type=&#39;text&#39; and @name=&#39;username&#39;]&lt;/pre&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It will find an &amp;lt;input&amp;gt; field that is both text-type and has the name &quot;username&quot;.&lt;/p&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;//button[@type=&#39;submit&#39; or text()=&#39;Login&#39;]&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It will locate a button&amp;nbsp;with either type=&quot;submit&quot; or text &quot;Login&quot;.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;6.&amp;nbsp;Parent-Child &amp;amp; Descendant XPath&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Direct Child (/)&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;To find elements that are direct children of a parent, you can write XPath as below.&lt;/p&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;//form/input&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;This XPath will find input fields that are direct children of the &amp;lt;form&amp;gt;.&lt;/p&gt;&lt;div&gt;&lt;b&gt;Any Descendant (//)&lt;/b&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;One can use given XPath to find&amp;nbsp;any input field inside a &amp;lt;div&amp;gt;, even if it is deeply nested.&lt;/p&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;//form/input&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;7.&amp;nbsp;Navigating the DOM (Parent, Sibling, Ancestors)&lt;/h3&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Moving to Parent (..)&lt;/b&gt;&lt;/h4&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;//input[@name=&#39;password&#39;]/..&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It will find the parent element of the password input field.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Finding Siblings&lt;/b&gt;&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Next Sibling (following-sibling)&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;//label[@for=&#39;username&#39;]/following-sibling::input
&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It will locate the input field immediately after the &quot;Username&quot; label.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Previous Sibling (preceding-sibling)&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;//input[@id=&#39;pass&#39;]/preceding-sibling::label
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It will locate the&amp;nbsp;label before the password input field.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;8.&amp;nbsp;XPath Using Position (first(), last(), [n])&lt;/h3&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Locate the first element&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;//input[1]
&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It will locate the first input field on the page.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Locate the last element&lt;/b&gt;&lt;/p&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;//table/tbody/tr[last()]&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Finds the last row in a table.&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Specific Position (nth element)&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;//input[2]
&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;This XPath will find the second input field from the page.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can refer to this&amp;nbsp;&lt;a href=&quot;https://devhints.io/xpath&quot; target=&quot;_blank&quot;&gt;xpath cheat sheet&lt;/a&gt;&amp;nbsp;which covers almost all functions, axes, predicts, expressions, and selectors.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Where to practice XPath?&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can use the &lt;a href=&quot;https://selectorshub.com/xpath-practice-page/&quot; target=&quot;_blank&quot;&gt;Selectoshub online practice page&lt;/a&gt; to try all possible variations of XPath.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Using XPath Axes in Selenium WebDriver With Examples&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can use XPath Axes to&amp;nbsp;navigate up, down, and sideways in the DOM. Using Axes,&amp;nbsp;you can traverse the hierarchy to locate elements dynamically.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;When to Use XPath Axes?&lt;/h3&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;When elements do not have any unique attributes like id or name.&lt;/li&gt;&lt;li&gt;When you need to locate an element relative to another.&lt;/li&gt;&lt;li&gt;When you are dealing with complex, nested structures.&lt;/li&gt;&lt;/ul&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;List of XPath Axes with example&lt;/h3&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6G8yfGVRtOs1oeYOjmc4Auy05g5DfPKppNubSM1vDm9lQZuSz4vJCsX2-3K2UR7HcRvZAfdypCk5yf8hJFU0eRCA3mu4wBQHoVO_dZoHdNqMTXk2DcMbNxMlsRw81RWC29kmFFTKYqwtBdAsdE8gOOeQTIgzc-qdvtKlt0lmKQkd7P4gxDRNoXjkiGSuc/s343/list%20of%20useful%20xpath%20axis.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;XPath Axis&quot; border=&quot;0&quot; data-original-height=&quot;343&quot; data-original-width=&quot;287&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6G8yfGVRtOs1oeYOjmc4Auy05g5DfPKppNubSM1vDm9lQZuSz4vJCsX2-3K2UR7HcRvZAfdypCk5yf8hJFU0eRCA3mu4wBQHoVO_dZoHdNqMTXk2DcMbNxMlsRw81RWC29kmFFTKYqwtBdAsdE8gOOeQTIgzc-qdvtKlt0lmKQkd7P4gxDRNoXjkiGSuc/w335-h400/list%20of%20useful%20xpath%20axis.png&quot; title=&quot;List of useful xpath axis to use in selenium automation testing&quot; width=&quot;335&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;child::&lt;/b&gt; -&amp;gt;&amp;nbsp;Selects Direct Children&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;//form/child::input (It will select all input fields inside the &amp;lt;form&amp;gt;.)&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;parent::&lt;/b&gt;&amp;nbsp;-&amp;gt; Selects Parent of an Element&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;: //input[@id=&#39;password&#39;]/parent::form (Finds the form that contains the password field.)&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;descendant::&lt;/b&gt; -&amp;gt;&amp;nbsp;Selects All Nested Elements&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;//div/descendant::input (Finds all input fields inside the &amp;lt;div&amp;gt;.)&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;ancestor&lt;/b&gt;:: -&amp;gt;&amp;nbsp;Selects All Ancestor Elements (Upwards Traversal)&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;: //input[@id=&#39;username&#39;]/ancestor::div (Finds the div container of the username input field.)&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;following::&lt;/b&gt; -&amp;gt;&amp;nbsp;Selects All Elements After the Current Element.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;: //label[@for=&#39;username&#39;]/following::input (Finds the first input field after the username label (i.e., the username input))&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;following-sibling::&lt;/b&gt; -&amp;gt;&amp;nbsp;Selects Next Sibling Elements&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;//label[@for=&#39;username&#39;]/following-sibling::input (Finds the username input field, which is the next sibling of the label.)&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;preceding&lt;/b&gt;:: -&amp;gt;&amp;nbsp;Selects All Elements Before the Current Element.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;: //input[@id=&#39;password&#39;]/preceding::label (Finds the label for username, which comes before the password input.)&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;preceding-sibling::&lt;/b&gt; -&amp;gt;&amp;nbsp;Selects Previous Sibling Elements.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;: //input[@id=&#39;password&#39;]/preceding-sibling::label (Finds the password label, which is the sibling before the password input field.)&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;self::&lt;/b&gt; -&amp;gt;&amp;nbsp;Selects the Current Element Itself.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;: //input[@id=&#39;username&#39;]/self::input (Finds itself (username input field))&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;For best practices, you can use&amp;nbsp;following-sibling:: and preceding-sibling:: to select nearby elements efficiently. Always prefer descendant:: for deep nested paths to avoid brittle XPath. Try to use ancestor:: to move up and find parent elements dynamically.&amp;nbsp;following:: and preceding:: are slower, so avoid using them if not necessary.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Handling Customized Dynamic XPath In Selenium WebDriver&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You need to customize XPath when the element&#39;s&amp;nbsp;attributes change frequently.&amp;nbsp;If an element&#39;s id, name, or class values are not static, Regular XPath expressions will not work for you. In such cases, you need to use advanced dynamic XPath.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here are a few smart and advanced XPath examples to build and handle dynamic XPath for an Element&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Using &lt;b&gt;contains()&amp;nbsp;&lt;/b&gt;for Partial Matching: //input[contains(@id, &#39;user_&#39;)]&lt;/li&gt;&lt;li&gt;Using &lt;b&gt;starts-with()&amp;nbsp;&lt;/b&gt;for Matching Beginning Text:&amp;nbsp;//input[starts-with(@id, &#39;user_&#39;)]&lt;/li&gt;&lt;li&gt;Using &lt;b&gt;text()&lt;/b&gt;&amp;nbsp;for Text-Based Matching:&amp;nbsp;//button[text()=&#39;Login&#39;]&lt;/li&gt;&lt;li&gt;Using &lt;b&gt;or &lt;/b&gt;and &lt;b&gt;and &lt;/b&gt;for Multiple Conditions:&amp;nbsp;//input[@type=&#39;text&#39; or @placeholder=&#39;Enter username&#39;]&lt;/li&gt;&lt;li&gt;Using &lt;b&gt;following-sibling::&lt;/b&gt;&amp;nbsp;to Locate Elements Dynamically: //label[text()=&#39;Username:&#39;]/following-sibling::input&lt;/li&gt;&lt;li&gt;Using &lt;b&gt;ancestor::&lt;/b&gt; to Find Parent Elements: //input[@id=&#39;pass_987&#39;]/ancestor::form&lt;/li&gt;&lt;li&gt;Using &lt;b&gt;last()&lt;/b&gt; to Get the Last Element in a List: //input[last()]&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;How to Use XPath in Java, Python, and C# With Selenium&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;For your knowledge, XPath is not dependent on any language. You can use the same XPath in all three languages.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Using XPath in Selenium With Java Example&lt;/h3&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;WebElement username = driver.findElement(By.xpath(&quot;//input[@id=&#39;username&#39;]&quot;));
    WebElement password = driver.findElement(By.xpath(&quot;//input[@type=&#39;password&#39;]&quot;));
    WebElement loginButton = driver.findElement(By.xpath(&quot;//button[contains(text(), &#39;Login&#39;)]&quot;));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Using XPath in Selenium With Python Example&lt;/h3&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;IWebElement username = driver.FindElement(By.XPath(&quot;//input[@id=&#39;username&#39;]&quot;));
    IWebElement password = driver.FindElement(By.XPath(&quot;//input[@type=&#39;password&#39;]&quot;));
    IWebElement loginButton = driver.FindElement(By.XPath(&quot;//button[contains(text(), &#39;Login&#39;)]&quot;));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Using XPath in Selenium With C# Example&lt;/h3&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 662.297px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;username = driver.find_element(By.XPATH, &quot;//input[@id=&#39;username&#39;]&quot;)
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;password = driver.find_element(By.XPATH, &quot;//input[@type=&#39;password&#39;]&quot;)
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;login_button = driver.find_element(By.XPATH, &quot;//button[contains(text(), &#39;Login&#39;)]&quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;h2&gt;Best XPath extensions and Plugins For Chrome Browser&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Finding XPath for each and every element is time-consuming, right? Here is a list of the top 4 free Chrome extensions for 2025 that you can use to find XPath of any web element.&lt;/p&gt;&lt;div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;a href=&quot;https://chromewebstore.google.com/detail/selectorshub-xpath-helper/ndgimibanhlabgdgjcpbbndiehljcpfh&quot; target=&quot;_blank&quot;&gt;SelectorsHub&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://chromewebstore.google.com/detail/selectorshub-xpath-helper/ndgimibanhlabgdgjcpbbndiehljcpfh&quot; target=&quot;_blank&quot;&gt;ChroPath&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://chromewebstore.google.com/detail/roborabbit-helper/hmpingmjkabbcfaiohochkfekgiiflff&quot; target=&quot;_blank&quot;&gt;Roborabbit Helper&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://chromewebstore.google.com/detail/selectorgadget/mhjhnkcfbdhnjickkkdbjoemdmbfginb&quot; target=&quot;_blank&quot;&gt;SelectorGadget&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;h2&gt;Frequently Asked Selenium Interview Questions on XPath&lt;/h2&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;XPath is a very important and crucial topic in an interview. Generally, interviewers are asking the following tricky questions.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;1. What is XPath in Selenium, and why do we use it?&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;In Selenium, XPath is a way to locate an element on the page when other locators like ID, name, or &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/selenium-find-element-by-class.html&quot; target=&quot;_blank&quot;&gt;find element by class name&lt;/a&gt; are not working. It allows you to navigate through the HTML structure and&amp;nbsp;pinpoint elements precisely.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;So, why use XPath?&lt;/p&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Some elements have dynamic changing attributes. XPath works well in this scenario.&lt;/li&gt;&lt;li&gt;It has built-in functions and methods to search elements by text, partial text,&amp;nbsp;parent-child relationships, or even positions.&lt;/li&gt;&lt;li&gt;It is super flexible compared to other locators.&lt;/li&gt;&lt;/ul&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;2.&amp;nbsp;What is the difference between Absolute XPath and Relative XPath?&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Absolute XPath&lt;/b&gt; is just like giving someone turn-by-turn directions from the homepage to a specific section. It is a full path from the main HTML tag to the element. This XPath will break if anything changes in the page structure.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;: /html/body/div[1]/table/tbody/tr[2]/td[1]&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Relative XPath&lt;/b&gt; is more flexible as it can search from anywhere in the document instead of the root. Less chances&amp;nbsp;to break when the UI updates.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;//table[@id=&#39;userTable&#39;]//tr[2]/td[1]&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;3. How do you handle dynamic elements with XPath?&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Sometimes, Element&#39;s attributes like ID and name keep changing when the page reloads. In such scenarios, we can use the following smart&amp;nbsp;techniques of XPath to handle them easily.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;contains()&lt;/b&gt;: We can use&amp;nbsp;contains() function when a part of attributes remain same&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;//input[contains(@id, &#39;email&#39;)]&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;starts-with()&lt;/b&gt;: If the attribute&#39;s initial part remains the same, we can use the starts-with() function.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;//button[starts-with(@class, &#39;submit-btn&#39;)]&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;ends-with()&lt;/b&gt;: One can match the end part of an attribute if it remains the same.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;: //input[ends-with(@class, &#39;txt&#39;)]&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;text()&lt;/b&gt;: It is useful when you are looking to locate an element based on visible text.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;//a[text()=&#39;Login&#39;]&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;last()&lt;/b&gt;: You can match the last matching element in a group using this function.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;: (//input[@type=&#39;text&#39;])[last()]&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;4.&amp;nbsp;How do you find a parent or sibling element using XPath?&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;We can use XPath axes to navigate up, down, and sideways in HTML&amp;nbsp;structure as follows.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;To find the parent element, we can use&amp;nbsp;parent::&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;: //input[@id=&#39;username&#39;]/parent::div&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;To find the next&amp;nbsp;sibling element, we can use the following-sibling::&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;: //label[text()=&#39;Username&#39;]/following-sibling::input&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;To find the previous sibling element, we can use&amp;nbsp;preceding-sibling::&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;: //input[@id=&#39;password&#39;]/preceding-sibling::label&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;These are very useful axes when a unique identifier of the element is not available. You can locate an element using the nearby element&#39;s reference.&lt;/p&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;5.&amp;nbsp;What are XPath operators, and how do they help?&lt;/h3&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;XPath also comes with handy operators that make searching even more powerful. Here is a list of operators with examples.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGdneGBR0dzRTJKlyaetFaargNZ7yWVyerROlpo2t1UyFEbysOfchCVTJQMoPfd_Ws4LNPnlTbuDPWOa8NDpio7HsIIQB75szLObpJoFxf3XqsYDhujzK-Bhf69Ou6Nsenb8zDTNoo-zhk_h-vTOFq5Dp9Z7uI_coEw8w5Klb5diFxbWn80LuWr_zQcDqv/s212/list%20of%20xpath%20operators%20to%20use%20in%20selenium%20automation.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;XPath operators&quot; border=&quot;0&quot; data-original-height=&quot;116&quot; data-original-width=&quot;212&quot; height=&quot;175&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGdneGBR0dzRTJKlyaetFaargNZ7yWVyerROlpo2t1UyFEbysOfchCVTJQMoPfd_Ws4LNPnlTbuDPWOa8NDpio7HsIIQB75szLObpJoFxf3XqsYDhujzK-Bhf69Ou6Nsenb8zDTNoo-zhk_h-vTOFq5Dp9Z7uI_coEw8w5Klb5diFxbWn80LuWr_zQcDqv/w320-h175/list%20of%20xpath%20operators%20to%20use%20in%20selenium%20automation.png&quot; title=&quot;List of useful xpath operators to build dynamic xpath&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;and Operator&lt;/b&gt;: You can use it to match both conditions.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example of and Operator&lt;/b&gt;: //input[@type=&#39;text&#39; and @name=&#39;email&#39;]&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;or Operator&lt;/b&gt;: Useful when looking to match either condition.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&amp;nbsp;or Operator&lt;/b&gt;:&amp;nbsp;//button[@id=&#39;submit&#39; or @class=&#39;btn&#39;]&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;= Operator&lt;/b&gt;: Check for exact match.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example of&amp;nbsp;= Operator&lt;/b&gt;:&amp;nbsp;//a[@href=&#39;login.html&#39;]&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;!= Operator&lt;/b&gt;:&amp;nbsp;Not equal to&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example of&amp;nbsp;!= Operator&lt;/b&gt;:&amp;nbsp;//input[@type!=&#39;password&#39;]&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can learn and read frequently asked &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/selenium-interview-questions-and-answers.html&quot; target=&quot;_blank&quot;&gt;Selenium Interview Questions and Answers&lt;/a&gt; if you are preparing for an interview.&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;XPath is like a Swiss Army knife for Selenium. It is so powerful, flexible and works very well when other locators struggle or fail. However, it is slower than&amp;nbsp;CSS Selectors. So use it&amp;nbsp;wisely.&amp;nbsp;If an element has a stable ID, name, tagname or Class, go for that first.&amp;nbsp;But when things get tricky, XPath is your best friend!&lt;/p&gt;&lt;/div&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2025/03/xpath-in-selenium.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR0yeaDh7K6QA4I6cKZ-cYz5LSYT8cA72cZy27UCG7QJ_D08bnvOCZKJbAB_TCVmFeV4JaMu8MVbZWp10B3g-cRC3165SgLnDKqNi-JrDYNup7bn77yS2Uhiqu0BCuT71I6h5GnxpmQ4nNLODka2mMs9UUVSJWRMLtoKeqM6U0ypHRxjTLXrzmib20BL7y/s72-w400-h209-c/How%20to%20find%20XPath%20in%20Selenium.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-1520204672212685296</guid><pubDate>Thu, 06 Mar 2025 06:47:00 +0000</pubDate><atom:updated>2025-03-06T21:57:11.143-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Appium</category><category domain="http://www.blogger.com/atom/ns#">Appium Android Examples</category><category domain="http://www.blogger.com/atom/ns#">Appium Tutorials</category><category domain="http://www.blogger.com/atom/ns#">mobile automation</category><category domain="http://www.blogger.com/atom/ns#">Selenium 3</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver</category><category domain="http://www.blogger.com/atom/ns#">WebDriver</category><category domain="http://www.blogger.com/atom/ns#">WebDriver Examples</category><category domain="http://www.blogger.com/atom/ns#">webdriver tutorials</category><title>UI Automator Viewer : Get Android App Element&#39;s XPath, ID, Name And className</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We learnt how to use &lt;b&gt;UI Automator Viewer&lt;/b&gt; in &lt;b&gt;&lt;a href=&quot;http://www.software-testing-tutorials-automation.com/2015/09/locating-android-app-elements-using-ui.html&quot;&gt;PREVIOUS POST&lt;/a&gt;&lt;/b&gt; to &lt;b&gt;locate and get properties details of android native software app&#39;s any element&lt;/b&gt;. Now we need to learn what are the different ways to locate elements of android software app and how to determine those locators to use them in test script. Most successful ways to &lt;b&gt;locate android software app&#39;s elements are&amp;nbsp;XPath, ID, Name And className&lt;/b&gt; so we will learn them rights now. Also we can use &lt;b&gt;findElements method of webdriver to locate element of android app&lt;/b&gt;.We will use &lt;b&gt;UI Automator Viewer to locate android app element&lt;/b&gt; and get it property and hierarchy&amp;nbsp;detail.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
&lt;b&gt;PREREQUISITES &lt;/b&gt;: Previous &lt;b&gt;&lt;a href=&quot;http://www.software-testing-tutorials-automation.com/2015/09/appium-tutorials.html&quot;&gt;9 STEPS&lt;/a&gt;&lt;/b&gt; of appium android software test automation tutorials should be completed.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Locating Android App Element By&amp;nbsp;XPath&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Earlier we learnt how to locate element by XPath in selenium webdriver software testing tool in &lt;b&gt;&lt;a href=&quot;http://www.software-testing-tutorials-automation.com/2014/01/how-to-locate-element-by-xpath-in.html&quot;&gt;THIS POST&lt;/a&gt;&lt;/b&gt; and also given different examples to write XPath of element in different ways in &lt;b&gt;&lt;a href=&quot;http://www.software-testing-tutorials-automation.com/2013/06/xpath-tutorials-identifying-xpath-for.html&quot;&gt;THIS POST&lt;/a&gt;&lt;/b&gt;. So i am suggesting you to refer both these posts before going ahead.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We will use android calculator app to get element&#39;s XPath in different ways. Supposing I need XPath of button 5. So i can write XPath in multiple ways for it as bellow.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
UI Automator Viewer screenshot for button 5 is as bellow. You can download&amp;nbsp;Android Calculator App from &lt;b&gt;&lt;a href=&quot;http://www.software-testing-tutorials-automation.com/2015/11/test-apps-to-use-in-appium-automation.html&quot;&gt;THIS PAGE&lt;/a&gt;&lt;/b&gt; if it is not available with you.&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjONHZDriP1AZexSkcYh-BAXJgDZKNu8sJUknd6mf3VOwBIXrVogdj6mXuh6DitBibRA9Uf2yrdJ3MzMQukvJs90_Dloc-2fRA9KX8ENNeR_rvTLVKIcv9W0YpHmc3RPbRKJln-pGK-f411/s1600/xpath+using+UI+Automator+Viewer.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;362&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjONHZDriP1AZexSkcYh-BAXJgDZKNu8sJUknd6mf3VOwBIXrVogdj6mXuh6DitBibRA9Uf2yrdJ3MzMQukvJs90_Dloc-2fRA9KX8ENNeR_rvTLVKIcv9W0YpHmc3RPbRKJln-pGK-f411/s400/xpath+using+UI+Automator+Viewer.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;1. XPath using class and text attribute :&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In above image you can see that button 5 has &lt;b&gt;text &lt;/b&gt;attribute with value = 5 which is unique. Class name is &lt;b&gt;android.widget.Button&lt;/b&gt;&amp;nbsp;which is same for all number buttons. So we can create XPath using text attribute value with class name as bellow.&lt;/div&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;xpath(&quot;//android.widget.Button[@text=&#39;5&#39;]&quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;2. XPath using class and resource-id :&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here&amp;nbsp;resource-id for button 5 is&amp;nbsp;com.android.calculator2:id/digit5. Trailing part (e.g digit5, digit4, digit7) of &lt;b&gt;resource-id&lt;/b&gt; is changing for every number buttons so we can use&amp;nbsp;contains function to get relative XPath of button 5 as bellow.&lt;/div&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;xpath(&quot;//android.widget.Button[contains(@resource-id,&#39;digit5&#39;)]&quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;3.&amp;nbsp;XPath using class,&amp;nbsp;text attribute&amp;nbsp;and resource-id&amp;nbsp;:&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We can use combination of&amp;nbsp;&lt;b&gt;text&amp;nbsp;&lt;/b&gt;attribute and&amp;nbsp;&lt;b&gt;resource-id&lt;/b&gt;&amp;nbsp;with class name to create unique XPath of element button 5 as bellow.&lt;/div&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;xpath(&quot;//android.widget.Button[contains(@resource-id,&#39;digit5&#39;) and @text=&#39;5&#39;]&quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;4.&amp;nbsp;XPath using class,&amp;nbsp;&lt;/b&gt;&lt;b&gt;text attribute&amp;nbsp;and&amp;nbsp;index&amp;nbsp;:&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We can use same approach as described in point 3 but with index number. Button 5 has index 1 but it is not unique as number buttons 0,2 and 8 has also same index with same class name. So we can include&amp;nbsp;&lt;b&gt;text&amp;nbsp;&lt;/b&gt;attribute with &lt;b&gt;index &lt;/b&gt;attribute&amp;nbsp;to locate number button 5.&lt;/div&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;xpath(&quot;//android.widget.Button[@text=&#39;5&#39; and @index=&#39;1&#39;]&quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;5. XPath using parent and child class hierarchy&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLpR1Fs_k4t6Ld2bE0iFN9wiKsaauXssDCApX24PGhAUaiqHlhAlSgVOR2woQokaytb7by2HuCWxHn4ZAibHpjk5DLvFRaOptn5HdlNozXKdj46ItA4Fww6kpJw0g0lawTfeFWQ279bUep/s1600/xpath+using+class+hierarchy.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;138&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLpR1Fs_k4t6Ld2bE0iFN9wiKsaauXssDCApX24PGhAUaiqHlhAlSgVOR2woQokaytb7by2HuCWxHn4ZAibHpjk5DLvFRaOptn5HdlNozXKdj46ItA4Fww6kpJw0g0lawTfeFWQ279bUep/s400/xpath+using+class+hierarchy.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
As you can see in above image, Parent class &lt;b&gt;android.widget.LinearLayout&lt;/b&gt; class with &lt;b&gt;index &lt;/b&gt;= 1 has buttons 4, 5, 6 and X. So we can locate that specific row by it&#39;s class index. Child element is member of class &lt;b&gt;android.widget.Button&lt;/b&gt; with &lt;b&gt;index&lt;/b&gt;&amp;nbsp;= 1. So we can format XPath using parent and child class hierarchy as bellow.&lt;/div&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;xpath(&quot;//android.widget.LinearLayout[@index=&#39;1&#39;]/android.widget.Button[@index=&#39;1&#39;]&quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;6. XPath using&amp;nbsp;content-desc&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3vjsq1fVxF6hIWTftgZrV1UIdVX_59_-dDQTdy_gj4vaNVi0kOHDZZN4pl-kTtVdN_fTbRtkwvzeGkM7i14IngvOkem0yEe8tMaIyJKgLhTtXw_QFjJXXvBYkoEWgdEYx5WNCG5uA0Mrx/s1600/xpath+using+content-desc.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;137&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3vjsq1fVxF6hIWTftgZrV1UIdVX_59_-dDQTdy_gj4vaNVi0kOHDZZN4pl-kTtVdN_fTbRtkwvzeGkM7i14IngvOkem0yEe8tMaIyJKgLhTtXw_QFjJXXvBYkoEWgdEYx5WNCG5uA0Mrx/s320/xpath+using+content-desc.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Supposing element has&amp;nbsp;&lt;b&gt;content-desc&lt;/b&gt; which is unique then you can use it to create XPath. Example : DELETE button has unique&amp;nbsp;&lt;b&gt;content-desc&lt;/b&gt;&amp;nbsp;= delete. So we can write XPath for delete button using it as bellow.&lt;/div&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;xpath(&quot;//android.widget.Button[@content-desc=&#39;delete&#39;]&quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;7. XPath using class name&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Note&amp;nbsp;&lt;/span&gt;&lt;/b&gt;: Using class name In By.className or By.xpath will works only if it is unique for element. If same class name is provided to multiple elements then it will not work.&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4rxXKy3VplS6y_kKubBWaJRYuwxDMg6ffDEjwMQ5FG90zuRXnhGGGuTufTNRFD4Sr9bYqQhSb-37dFjNhW51tXgOKzEbTMSI_hEZw6tnRTOAb4SyJFD_9o0XUVy-rBJ2h5bf41uOcnv53/s1600/xpath+using+class+name.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;123&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4rxXKy3VplS6y_kKubBWaJRYuwxDMg6ffDEjwMQ5FG90zuRXnhGGGuTufTNRFD4Sr9bYqQhSb-37dFjNhW51tXgOKzEbTMSI_hEZw6tnRTOAb4SyJFD_9o0XUVy-rBJ2h5bf41uOcnv53/s320/xpath+using+class+name.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If software application&#39;s element has a class name and it is unique for element then you can use class name only to create XPath. See above image. Options button has class name&amp;nbsp;&lt;b&gt;android.widget.ImageButton&lt;/b&gt; which is unique. So we can use it only to create xpath as bellow.&lt;/div&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;xpath(&quot;//android.widget.ImageButton&quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Here is the &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/xpath-in-selenium.html&quot; target=&quot;_blank&quot;&gt;latest tutorial for XPath in Selenium&lt;/a&gt; to locate element by attributes, Axes, operators, and dynamic XPath generation.&lt;/p&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Locating Android App Element By&amp;nbsp;ID&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Earlier we learnt how to locate element by ID for web application in &lt;b&gt;&lt;a href=&quot;http://www.software-testing-tutorials-automation.com/2014/01/how-to-locate-elements-by-id-in.html&quot;&gt;THIS POST&lt;/a&gt;&lt;/b&gt;. We can locate elements by ID in android app too. We can use resource-id as a id. Example is as bellow.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
resource-id for button 5 is &quot;com.android.calculator2:id/digit5&quot; so we can locate to it by id as bellow.&lt;/div&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;id(&quot;com.android.calculator2:id/digit5&quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Locating Android App Element By&amp;nbsp;className&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Same way, We can use class name to locate element if it is unique.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4rxXKy3VplS6y_kKubBWaJRYuwxDMg6ffDEjwMQ5FG90zuRXnhGGGuTufTNRFD4Sr9bYqQhSb-37dFjNhW51tXgOKzEbTMSI_hEZw6tnRTOAb4SyJFD_9o0XUVy-rBJ2h5bf41uOcnv53/s1600/xpath+using+class+name.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;123&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4rxXKy3VplS6y_kKubBWaJRYuwxDMg6ffDEjwMQ5FG90zuRXnhGGGuTufTNRFD4Sr9bYqQhSb-37dFjNhW51tXgOKzEbTMSI_hEZw6tnRTOAb4SyJFD_9o0XUVy-rBJ2h5bf41uOcnv53/s320/xpath+using+class+name.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Class name for above option button is &quot;android.widget.ImageButton&quot;. We can locate it using className as bellow.&lt;/div&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;By.className(&quot;android.widget.ImageButton&quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Locating Android App element by Name&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
It is possible to locate element by name if element contains unique text.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYkrNhJRo7uAfaIdbjGzss5RUc4XJOW3mCyd-c0FBBzS1vyr8sobBmBy7H8FqcPPdhPRhZKul15MDwxMUTh3eW3SqLnRwpWhCykxdSQyH9HlV6uauIXh047emhJZLLehLNOmZ8iIRHdV1O/s1600/find+android+element+by+name.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;111&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYkrNhJRo7uAfaIdbjGzss5RUc4XJOW3mCyd-c0FBBzS1vyr8sobBmBy7H8FqcPPdhPRhZKul15MDwxMUTh3eW3SqLnRwpWhCykxdSQyH9HlV6uauIXh047emhJZLLehLNOmZ8iIRHdV1O/s320/find+android+element+by+name.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
If you see in above image, button Equals has text value &quot;=&quot;. So we can locate it by name using bellow given syntax.&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;By.name(&quot;=&quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Locating element by&amp;nbsp;findElements&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If you inspect all buttons of android calculator app, All the buttons has same class &quot;android.widget.Button&quot;. If you know, findElements method is useful to get list of all the matching elements from current page as per given element locator mechanism. &lt;b&gt;&lt;a href=&quot;http://www.software-testing-tutorials-automation.com/2014/02/selenium-webdriver-difference-between.html&quot;&gt;VIEW MORE DETAIL&lt;/a&gt;&lt;/b&gt; on findElements. So here we can collect list of all buttons using&amp;nbsp;findElements and store list using java&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
List interface. Then we access required element using get() method of List interface.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Array list Index IDs of button elements of &quot;android.widget.Button&quot; class is as bellow.&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8MZE_5rjBKi8maJax256oMCVCK_WQtKChyUbI1wfZxGDvg9fRqjqpgVeSAjUHRflaEfnvp2-_rKJdq5lZIjvfQjE4WGHFoJzq5kJCQ3wr-i7nljRIw96MoNCwl0kN2bNetvlZmiu8EUEa/s1600/findelements+to+store+list+of+android+elements.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;363&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8MZE_5rjBKi8maJax256oMCVCK_WQtKChyUbI1wfZxGDvg9fRqjqpgVeSAjUHRflaEfnvp2-_rKJdq5lZIjvfQjE4WGHFoJzq5kJCQ3wr-i7nljRIw96MoNCwl0kN2bNetvlZmiu8EUEa/s400/findelements+to+store+list+of+android+elements.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;List&amp;lt;WebElement&amp;gt; calcButtons = driver.findElements(By.xpath(&quot;//android.widget.Button&quot;));&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Above given syntax will store list of all buttons in list &lt;b&gt;calcButtons &lt;/b&gt;with bellow given array list index ids. Bellow given table illustrate array index ids for different buttons of calculator application.&lt;/div&gt;
&lt;br /&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;1&quot; cellspacing=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;thead&gt;

&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;Button&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;Array index ID&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
DELETE&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
0&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
7&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
1&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
8&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
2&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
9&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;3&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
÷(divide)&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;4&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
4&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;5&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
5&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;6&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
6&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;7&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
×(multiply)&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;8&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
1&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;9&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
2&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;10&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
3&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
11&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
−(minus)&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;12&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
.(point)&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;13&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
0&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;14&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
=(equals)&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;15&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
+(plus)&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;16&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
So now we can access required button using it&#39;s index which is stored in list&amp;nbsp;&lt;b&gt;calcButtons&lt;/b&gt;. Means if you wants to tap on button 5 then you can use bellow given syntax.&lt;/div&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;calcButtons.get(6).click();&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here 6 is list index id of button 5 as shown in above table.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
So all these are different ways to locate android software app elements. We will use all these element locator methods practically in our test scripts which I will publish in upcoming steps.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;&lt;a href=&quot;http://www.software-testing-tutorials-automation.com/2015/09/locating-android-app-elements-using-ui.html&quot;&gt;&amp;lt;&amp;lt; PREVIOUS&lt;/a&gt;&amp;nbsp;||&amp;nbsp;&lt;/b&gt;&lt;b&gt;&lt;a href=&quot;http://www.software-testing-tutorials-automation.com/2015/10/how-to-find-apk-file-package-name-and.html&quot;&gt;NEXT &amp;gt;&amp;gt;&lt;/a&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>http://software-testing-tutorials-automation.blogspot.com/2015/10/ui-automator-viewer-get-android-app.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjONHZDriP1AZexSkcYh-BAXJgDZKNu8sJUknd6mf3VOwBIXrVogdj6mXuh6DitBibRA9Uf2yrdJ3MzMQukvJs90_Dloc-2fRA9KX8ENNeR_rvTLVKIcv9W0YpHmc3RPbRKJln-pGK-f411/s72-c/xpath+using+UI+Automator+Viewer.png" height="72" width="72"/><thr:total>32</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-2341793106973067453</guid><pubDate>Wed, 05 Mar 2025 09:14:00 +0000</pubDate><atom:updated>2025-03-05T01:24:28.880-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">selenium webdriver</category><title>Selenium Supported Languages: A Complete Guide</title><description>&lt;p&gt;Selenium is arguably the crowned King of the automation testing tools today and one of its critical advantages is multi-language support. As an automation tester, regardless of your expertise level, it’s necessary to know what languages Selenium supports so you can select the best for your project.&lt;/p&gt;&lt;p&gt;In this article, we will discuss all the programming languages that are supported by Selenium, their pros and cons, and how to select the best one for your automated testing needs.&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;List of Selenium WebDriver Supported Programming Languages&lt;/h2&gt;&lt;div&gt;&lt;div&gt;Now, let&#39;s explore the languages supported by Selenium WebDriver:&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;1. Java&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Popular language&lt;/b&gt;: It is one of the most widely used languages in Selenium automation testing.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Good Community Support&lt;/b&gt;: It has a good developer and tester community&amp;nbsp;support and has an&amp;nbsp;extensive library.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Easy to Integrate&lt;/b&gt;: You can integrate it easily with TestNG, JUnit, and Maven.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Fast test execution&lt;/b&gt;: Test scripts are executed faster in Java.&lt;/li&gt;&lt;/ul&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Example:&lt;/h4&gt;&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;WebDriver driver = new ChromeDriver();
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.get(&quot;https://www.google.com&quot;);
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;System.out.println(&quot;Title: &quot; + driver.getTitle());
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.quit();&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;2.&amp;nbsp;Python&lt;/h3&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Simple syntax, easy to learn&lt;/b&gt;: It has simpler syntax compared to other languages. Also, it is easy to learn for beginners.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Works well with PyTest and Behave for BDD&lt;/b&gt;: It is easy to integrate with&amp;nbsp;powerful testing framework&amp;nbsp;PyTest and&amp;nbsp;Behave to execute&amp;nbsp;parameterized tests and&amp;nbsp;parallel execution.&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;&lt;/p&gt;&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;from selenium import webdriver

driver = webdriver.Chrome()
driver.get(&quot;https://www.google.com&quot;)
print(&quot;Title:&quot;, driver.title)
driver.quit&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;3.&amp;nbsp;C#&lt;/h3&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Popular among .NET developers&lt;/b&gt;: It is one of the most popular language&amp;nbsp;among .NET developers who are working in Selenium automation testing.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Easy to Integrate:&lt;/b&gt;&amp;nbsp;You can integrate it easily with the NUnit and MSTest frameworks.&lt;/li&gt;&lt;li&gt;You can use it for&amp;nbsp;enterprise-level applications.&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;:&lt;/p&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

class Program {
    static void Main() {
        IWebDriver driver = new ChromeDriver();
        driver.Navigate().GoToUrl(&quot;https://www.google.com&quot;);
        Console.WriteLine(&quot;Title: &quot; + driver.Title);
        driver.Quit();
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;4. JavaScript (Node.js with WebDriverIO)&lt;/h3&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;It is an Ideal language for full-stack developers who are using JavaScript.&lt;/li&gt;&lt;li&gt;It works well with different frameworks like&amp;nbsp;Mocha, Jasmine, and Protractor.&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;&lt;/p&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;const { Builder } = require(&#39;selenium-webdriver&#39;);

(async function example() {
    let driver = await new Builder().forBrowser(&#39;chrome&#39;).build();
    await driver.get(&#39;https://www.google.com&#39;);
    let title = await driver.getTitle();
    console.log(&quot;Title:&quot;, title);
    await driver.quit();
})();
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;5.&amp;nbsp;Ruby&lt;/h3&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;It is popular among testers who are looking to perform&amp;nbsp;behavior-driven testing with Cucumber.&lt;/li&gt;&lt;li&gt;It has very simple and elegant syntax.&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;:&lt;/p&gt;&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;require &#39;selenium-webdriver&#39;

driver = Selenium::WebDriver.for :chrome
driver.navigate.to &quot;https://www.google.com&quot;
puts &quot;Title: #{driver.title}&quot;
driver.quit&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;6.&amp;nbsp;PHP&amp;nbsp;&lt;/h4&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;PHP is less famous with Selenium, but it is still supported if you love to code in PHP.&lt;/li&gt;&lt;li&gt;It is suitable&amp;nbsp;for web-based test automation in PHP projects.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;b&gt;Example&lt;/b&gt;:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&amp;lt;?php
require &#39;vendor/autoload.php&#39;;
use Facebook\WebDriver\Chrome\ChromeDriver;
use Facebook\WebDriver\WebDriverBy;

$driver = ChromeDriver::start();
$driver-&amp;gt;get(&quot;https://www.google.com&quot;);
echo &quot;Title: &quot; . $driver-&amp;gt;getTitle();
$driver-&amp;gt;quit();&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;7. Perl&lt;/h3&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;It is also less commonly used language. But selenium supports it so it is necessary to mention it.&lt;/li&gt;&lt;li&gt;Best for testers and developers who are familiar with Perl scripting.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;use Selenium::Remote::Driver;

my $driver = Selenium::Remote::Driver-&amp;gt;new(browser_name =&amp;gt; &#39;chrome&#39;);
$driver-&amp;gt;get(&#39;https://www.google.com&#39;);
print &quot;Title: &quot; . $driver-&amp;gt;get_title() . &quot;\n&quot;;
$driver-&amp;gt;quit();&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;How to Choose the Right Language for Selenium?&lt;/h2&gt;&lt;div&gt;If you are confused in language selection for the selenium project, you need to consider many different factors. Choosing the right language for Selenium is just like selecting the best tool for the job. You need something comfortable to you, fulfill your need, and easy to use, right? Here is a step-by-step guide on how to choose the right language.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;First of all, let&#39;s see quickly which language is best for you.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Go with Java&lt;/b&gt; if you want scalability and performance.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Choose Python&lt;/b&gt; if you want simplicity and quick test automation.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Pick C#&lt;/b&gt; if you&#39;re working in a Microsoft environment.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Use JavaScript&lt;/b&gt; if your app is web-based and built in JavaScript.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;Now let&#39;s see a detailed description on how to select the best language for Selenium.&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;1. What’s Your Comfort Zone?&lt;/h3&gt;&lt;div&gt;First thing first. Which language is comfortable for you? If you are already comfortable with Java, C#, or Python, you can start with it. Learning a new language for Selenium is not necessary&amp;nbsp;unless there’s a strong reason to switch.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;2. The Most Popular Choices&lt;/h3&gt;&lt;div&gt;As we earlier discussed, Selenium supports multiple languages. But here is a list of languages that are used most with selenium in 2025.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Java&lt;/b&gt;:&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Pros&lt;/b&gt;: It is the most widely used language with Selenium. You will find tons of resources, great community support, and highly scalable.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Cons&lt;/b&gt;: It is&amp;nbsp;a little bit verbose. It is&amp;nbsp;cumbersome to write and maintain tests in Java.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Python&lt;/b&gt;:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Pros&lt;/b&gt;: It is very simple, easy to write, and great to write quick automation scripts.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Cons&lt;/b&gt;: However, it sometimes lags behind Java in feature updates.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Pros&lt;/b&gt;: If you are working with Microsoft technologies, C# is a great pick.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Cons&lt;/b&gt;:&amp;nbsp;Smooth integration with Visual Studio, but not as commonly used as Java.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;JavaScript (Node.js)&lt;/b&gt;:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Pros&lt;/b&gt;: Ideal for web-based projects. If your app is built in JavaScript, this might be the best choice.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Cons&lt;/b&gt;: Async programming can be tricky for beginners.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;3. What Else Are You Using?&lt;/h3&gt;&lt;div&gt;Think about the bigger picture. What other tools or frameworks are you going to use with Selenium like&amp;nbsp;TestNG, JUnit, PyTest, or Mocha?&amp;nbsp;Some languages work better with certain testing frameworks like JUnit, and TestNG works better with Java. If you already use such tools, then it is best to select the language based on them.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;4. Community &amp;amp; Support Matter!&lt;/h3&gt;&lt;div&gt;If you select an odd language, you will get stuck when a problem arises as no one will be there to help you.&amp;nbsp;Java and Python have massive Selenium communities, meaning more tutorials, documentation, and Stack Overflow answers when things go sideways.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;5.&amp;nbsp;Speed &amp;amp; Performance&lt;/h3&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;If you’re running large, complex test suites, you can choose Java because it is usually the fastest in execution.&lt;/li&gt;&lt;li&gt;If you need something lightweight and easy to maintain, Python is a great pick.&lt;/li&gt;&lt;li&gt;If your app is built in JavaScript, JS (Node.js) will be a seamless and best fit for you.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;6.&amp;nbsp;What’s Your Long-Term Plan?&lt;/h3&gt;&lt;div&gt;If you are a freelancer or looking for a job in automation, then Java and Python are the best languages for Selenium because both of them are dominating the job market. But if you are already working with some company and they are working with another language, then you can go with it.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;At the end of the day, the best language is the one that helps you get the job done without unnecessary headaches. So, what’s your pick?&amp;nbsp;Let me know in the comments!&lt;/p&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2025/03/selenium-supported-languages.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-7703604965904671880</guid><pubDate>Wed, 05 Mar 2025 04:55:00 +0000</pubDate><atom:updated>2025-03-04T20:56:06.328-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">selenium interview questions and answers</category><title>Selenium Interview Questions and Answers</title><description>&lt;p&gt;Are you preparing for an interview for a Selenium automation testing Job in 2025?&amp;nbsp;Whether you&#39;re just a&amp;nbsp;&lt;b&gt;beginner &lt;/b&gt;in Selenium or have &lt;b&gt;3 Years, 5 years, or 10 years of experience&lt;/b&gt; in automation testing,&amp;nbsp;being well-prepared before an interview can make all the difference. Selenium is universally used and one of the most popular&amp;nbsp;&lt;b&gt;automation testing tools&lt;/b&gt;, and companies are always looking for skilled testers and developers who have a strong understanding of it.&amp;nbsp;&lt;/p&gt;&lt;p&gt;To help you prepare, I have compiled a set of commonly asked &lt;b&gt;Selenium interview questions and answers&lt;/b&gt; based on actual Selenium automation problems and industry best practices. I have automated several projects and have assisted teams in resolving real-world problems with Selenium automation. These are real answers drawn from real experience because I know what works and what does not in real life.&lt;/p&gt;&lt;p&gt;No matter what level of knowledge a person has, these questions seem to encapsulate everything from basic core understanding to advanced level framework building tasks done by a test automation engineer. Whether you are looking for a &lt;b&gt;QA &lt;/b&gt;engineer position, &lt;b&gt;test automation developer&lt;/b&gt;, or an &lt;b&gt;SDET&lt;/b&gt;, this information will definitely help you in your next interview.&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Basic Selenium Interview Questions&lt;/h2&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;1. What is Selenium?&lt;/h3&gt;&lt;p&gt;Selenium is a free automation testing tool that was initially developed by Jason Huggins. It is used to test web applications on different browsers and platforms. It is not only a browser automation tool, but you can automate your web-based repetitive tasks as well using Selenium.&lt;/p&gt;&lt;p&gt;You can use it to automate testing across several programming languages to develop test scripts. It also supports cross-browser and cross-platform testing using Selenium Grid. You can run Selenium tests on different browsers like Chrome, Firefox, Edge, Opera, and Safari to check browser compatibility. Also, you can run test scripts on different OS easily like&amp;nbsp;Windows, Linux, and mac OS.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Unlike other automation tools, it interacts with browsers natively just like a real user. So it is easy to find UI level bugs as well.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;2. What are the different components of Selenium?&lt;/h3&gt;&lt;div&gt;&lt;div&gt;Selenium consists of four main components:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Selenium IDE&lt;/b&gt; – Shinya Kasatani developed it in 2006. Selenium IDE is an easy-to-use, open source browser extension that is used to record and play back test scripts.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Selenium WebDriver&lt;/b&gt; – Selenium WebDriver is a very popular and powerful tool for programmatically automating browser interactions.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Selenium Grid&lt;/b&gt; – Used for parallel execution of tests across multiple machines and browsers.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Selenium RC (Deprecated)&lt;/b&gt; – The old version of Selenium WebDriver.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;3. How does Selenium WebDriver work?&lt;/h3&gt;&lt;div&gt;Selenium WebDriver interacts with the browser using a browser-specific driver, i.e. ChromeDriver for Chrome,&amp;nbsp;geckodriver for Firefox, etc. &lt;b&gt;Selenium 3&lt;/b&gt; was using&amp;nbsp;JSON Wire Protocol to communicate with browsers.&amp;nbsp;&lt;span style=&quot;box-sizing: border-box; margin: 0px; padding: 0px;&quot;&gt;However, the newer version,&amp;nbsp;&lt;strong&gt;Selenium 4,&lt;/strong&gt;&lt;/span&gt;&amp;nbsp;primarily uses the W3C WebDriver protocol to&amp;nbsp;send commands and automate actions like&amp;nbsp;clicking, typing, and navigating web pages.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;4. What are the advantages of using Selenium for automation testing?&lt;/h3&gt;&lt;div&gt;Here are the main advantages that you can explain to the interviewer.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Cost Effective&lt;/b&gt;: It is open-source and free, which is the main advantage.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Multi Language Support&lt;/b&gt;: No language specific dependency. It supports multiple programming languages.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Platform Independent&lt;/b&gt;: No browser specific dependency. It supports multiple browsers.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Saves Time&lt;/b&gt;: Selenium Grid allows for parallel test execution, which can save you significant time.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Flexible &amp;amp; Easy Integration&lt;/b&gt;: Works with various testing frameworks (TestNG, JUnit, NUnit, Jenkins CI/CD, etc.)&lt;/li&gt;&lt;li&gt;&lt;b&gt;Active Community Support&lt;/b&gt;: Wide community support. Easy to find solutions online.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Automate Tests as a Real User Do&lt;/b&gt;: It interacts with browsers directly. Same as a real user does.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Create Framework As per Your Convenience&lt;/b&gt;: You can create different frameworks like data-driven, keyword-driven,&amp;nbsp;Hybrid, etc, easily, as per your requirement.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;5. What are the limitations of Selenium?&lt;/h3&gt;&lt;div&gt;Main limitations are&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Cannot automate desktop applications.&lt;/li&gt;&lt;li&gt;Limited support to test mobile apps (needs Appium for that)&lt;/li&gt;&lt;li&gt;No built-in reporting feature.&lt;/li&gt;&lt;li&gt;Cannot handle captchas and OTPs directly&lt;/li&gt;&lt;li&gt;It is challenging to handle pop-ups and dynamic web elements in Selenium.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;6. What programming languages does Selenium support?&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Selenium supports Java, Python, C#, Ruby, and JavaScript.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;7. What types of applications can Selenium automate?&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It can automate web applications only. You can test mobile apps with the help of Appium. You need third-party tools to automate desktop applications.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;8. How do you set up Selenium WebDriver in a project?&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;li&gt;Download and install Java or Python.&lt;/li&gt;&lt;li&gt;Install Eclipse or&amp;nbsp;PyCharm IDE as per the programming language you are working on.&lt;/li&gt;&lt;li&gt;Install Selenium WebDriver using Maven (Java) or pip (Python).&lt;/li&gt;&lt;li&gt;Download the required browser driver (e.g., ChromeDriver for Chrome).&lt;/li&gt;&lt;li&gt;Write and execute your test script.&lt;/li&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;9. What are the different locators in Selenium?&lt;/h3&gt;&lt;div&gt;&lt;div&gt;Selenium provides 8 locators to find web elements:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;ID &lt;/b&gt;– driver.findElement(By.id(&quot;username&quot;))&lt;/li&gt;&lt;li&gt;&lt;b&gt;Name &lt;/b&gt;– driver.findElement(By.name(&quot;email&quot;))&lt;/li&gt;&lt;li&gt;&lt;b&gt;Class Name&lt;/b&gt; – driver.findElement(By.className(&quot;login-btn&quot;))&lt;/li&gt;&lt;li&gt;&lt;b&gt;Tag Name&lt;/b&gt; – driver.findElement(By.tagName(&quot;input&quot;))&lt;/li&gt;&lt;li&gt;&lt;b&gt;Link Text&lt;/b&gt; – driver.findElement(By.linkText(&quot;Click Here&quot;))&lt;/li&gt;&lt;li&gt;&lt;b&gt;Partial Link Text&lt;/b&gt; – driver.findElement(By.partialLinkText(&quot;Click&quot;))&lt;/li&gt;&lt;li&gt;&lt;b&gt;CSS Selector&lt;/b&gt; – driver.findElement(By.cssSelector(&quot;#login&quot;))&lt;/li&gt;&lt;li&gt;&lt;b&gt;XPath &lt;/b&gt;– driver.findElement(By.xpath(&quot;//input[@id=&#39;password&#39;]&quot;))&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;10. What is the difference between findElement() and findElements()?&lt;/h3&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;findElement() method will return a single Web Element&amp;nbsp;(throws an error if element not found)&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;WebElement element = driver.findElement(By.id(&quot;login&quot;)); // Returns a single element.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;findElements() method is used to get a list of Web Elements (returns an empty list if element not found).&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;List&amp;lt;WebElement&amp;gt; elements = driver.findElements(By.tagName(&quot;a&quot;)); // Returns a list of links&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;11. What is the difference between driver.get() and driver.navigate().to()?&lt;/h3&gt;&lt;div&gt;&lt;p&gt;driver.get(&quot;URL&quot;): You can use it to load a new webpage and wait until it’s fully loaded.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Example&lt;/b&gt;: driver.get(&quot;https://example.com&quot;);&lt;/p&gt;&lt;p&gt;driver.navigate().to(&quot;URL&quot;) – It is similar to the get() method, but provides additional navigation features like&amp;nbsp;&lt;b&gt;back, forward, and refresh&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Example&lt;/b&gt;: driver.navigate().to(&quot;https://example.com&quot;);&lt;/p&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;12. How do you handle browser navigation in Selenium?&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;We can use the navigate() method for browser navigations.&lt;/p&gt;&lt;div&gt;&lt;b&gt;Examples&lt;/b&gt;:&lt;/div&gt;&lt;p&gt;To go back to the previous page, we can use driver.navigate().back();&amp;nbsp;&lt;/p&gt;&lt;p&gt;We can use driver.navigate().forward(); to go forward.&lt;/p&gt;&lt;p&gt;This syntax is used to refresh the page: driver.navigate().refresh();&amp;nbsp;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;13. How do you handle different types of waits in Selenium?&lt;/h3&gt;&lt;div&gt;We mainly use 3 types of waits in Selenium tests as below.&lt;/div&gt;&lt;div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;1. Implicit Wait&lt;/b&gt;&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Implicit wait is used to wait for elements globally.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example of&amp;nbsp;Implicit Wait&lt;/b&gt;: Given syntax will&amp;nbsp;wait for 10 seconds while page is loading.&lt;/p&gt;&lt;p&gt;driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);&lt;/p&gt;&lt;b&gt;2. Explicit Wait&lt;/b&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Explicit wait is used to wait for specific conditions.&lt;/p&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example of&amp;nbsp;Explicit Wait&lt;/b&gt;: Given syntax&amp;nbsp;will wait for 10 seconds for the element with the &#39;login&#39; id to be visible.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(&quot;login&quot;)));&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;3. Fluent Wait&lt;/b&gt;&lt;/h4&gt;&lt;/div&gt;&lt;div&gt;Similar to Explicit Wait but with polling intervals.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;14. What is the difference between implicit wait and explicit wait?&lt;/h3&gt;&lt;div&gt;The main differences between implicit and explicit wait are given below.&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Implicit Wait&lt;/h4&gt;&lt;div&gt;&lt;b&gt;Applies to&lt;/b&gt;: All elements globally.&lt;/div&gt;&lt;div&gt;&lt;b&gt;Usage&lt;/b&gt;:&amp;nbsp;driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);&lt;/div&gt;&lt;div&gt;&lt;b&gt;Checks conditions?&lt;/b&gt;:&amp;nbsp;No&lt;/div&gt;&lt;div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Explicit wait&lt;/h4&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Applies to&lt;/b&gt;: Specific elements&lt;/div&gt;&lt;div&gt;&lt;b&gt;Usage&lt;/b&gt;: WebDriverWait wait = new WebDriverWait(driver, 10);&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Checks conditions?&lt;/b&gt;: Yes (e.g., element visibility, clickable, etc.)&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;15. What is a Fluent Wait in Selenium?&lt;/h3&gt;&lt;div&gt;&lt;div&gt;A Fluent Wait in Selenium is a type of dynamic wait that allows you to specify&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;The &lt;strong data-end=&quot;118&quot; data-start=&quot;92&quot;&gt;maximum amount of time&lt;/strong&gt; to wait for a condition,&amp;nbsp;&lt;/li&gt;&lt;li&gt;The &lt;b&gt;polling frequency&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Ignoring specific exceptions&lt;/b&gt; while waiting.&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;Wait&amp;lt;WebDriver&amp;gt; wait = new FluentWait&amp;lt;&amp;gt;(driver)
    .withTimeout(Duration.ofSeconds(10))
    .pollingEvery(Duration.ofSeconds(1))
    .ignoring(NoSuchElementException.class);&lt;/span&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;16. How do you handle pop-ups and alerts in Selenium?&lt;/h3&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;We can handle pop-ups and alerts using the Alert interface. We can use the accept() method to accept or click on the OK button, the dismiss() method to dismiss/cancel the alert. Also, it is possible to type text in the text field of alert using sendKeys() method.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here is an example.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span class=&quot;hljs-type&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;Alert&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;alert&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; driver.switchTo().alert();
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;alert.accept(); &lt;span class=&quot;hljs-comment&quot;&gt;// Click OK  &lt;/span&gt;
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;alert.dismiss(); &lt;span class=&quot;hljs-comment&quot;&gt;// Click Cancel  &lt;/span&gt;
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;alert.sendKeys(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Hello&quot;&lt;/span&gt;); &lt;span class=&quot;hljs-comment&quot;&gt;// Send text  &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;17. How do you work with multiple browser windows in Selenium?&lt;/h3&gt;&lt;div&gt;We can use the getWindowHandles() method to switch between windows.&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Example:&lt;/h4&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;String mainWindow = driver.getWindowHandle();
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;for (String window : driver.getWindowHandles()) {
    &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.switchTo().window(window);
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;18. What is the difference between switchTo().window() and switchTo().frame()?&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;Difference between&amp;nbsp;switchTo().window() and switchTo().frame() is as below.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;switchTo().window(&quot;windowID&quot;)&lt;/b&gt;: It is used to switch between browser tabs/windows.&lt;/li&gt;&lt;li&gt;&lt;b&gt;switchTo().frame(&quot;frameID&quot;):&lt;/b&gt;&amp;nbsp;It is used to switch&amp;nbsp;to an iframe on the page.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;19. How do you handle dropdowns in Selenium?&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;We can use the Select class to handle alerts in Selenium. Here is an example on how to select dropdown options using visible text, value, and index.&lt;/p&gt;&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span class=&quot;hljs-type&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;Select&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;dropdown&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hljs-title class_&quot;&gt;Select&lt;/span&gt;(driver.findElement(By.id(&lt;span class=&quot;hljs-string&quot;&gt;&quot;dropdown&quot;&lt;/span&gt;)));
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;dropdown.selectByVisibleText(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Option 1&quot;&lt;/span&gt;);
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;dropdown.selectByValue(&lt;span class=&quot;hljs-string&quot;&gt;&quot;option1&quot;&lt;/span&gt;);
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;dropdown.selectByIndex(&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;);&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;20. How do you select a value from a dropdown using Selenium?&lt;/h3&gt;&lt;div&gt;There are three ways to select a value from a dropdown.&lt;/div&gt;&lt;div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;selectByVisibleText(&quot;Option&quot;)&lt;/li&gt;&lt;li&gt;selectByValue(&quot;option1&quot;)&lt;/li&gt;&lt;li&gt;selectByIndex(0)&lt;/li&gt;&lt;/ol&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;:&lt;/p&gt;&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span class=&quot;hljs-type&quot;&gt;Select&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;dropdown&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hljs-title class_&quot;&gt;Select&lt;/span&gt;(driver.findElement(By.id(&lt;span class=&quot;hljs-string&quot;&gt;&quot;dropdown&quot;&lt;/span&gt;)));
dropdown.selectByVisibleText(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Java&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Selenium WebDriver Questions&lt;/h2&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;21 What is WebDriver in Selenium?&lt;/h3&gt;&lt;div&gt;Selenium WebDriver is a browser automation framework. Simply, it automates the browsers. It is open-source so you can use it for free. It allows you to&amp;nbsp;interact with web applications just like a real user. It acts as a mediator to&amp;nbsp;send commands to web browsers and execute actions like clicking buttons, typing text in a textbox, navigating between pages, and many more actions.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here are key features of WebDriver:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;It can directly communicate with the browser.&lt;/li&gt;&lt;li&gt;It supports multiple browsers like&amp;nbsp;&lt;b&gt;Chrome, Firefox, Edge, Safari,&lt;/b&gt; etc.&lt;/li&gt;&lt;li&gt;Works with multiple programming languages like&amp;nbsp;&lt;b&gt;Java, Python, C#, JavaScript&lt;/b&gt;, etc.&lt;/li&gt;&lt;li&gt;You can easily use it on different OS like Windows, Linux, and Mac.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;WebDriver is one of the most commonly used components of Selenium framework. You can use it to perform &lt;b&gt;UI testing, regression testing,&amp;nbsp;functional testing,&amp;nbsp;cross-browser testing,&amp;nbsp;database testing, and parallel testing&lt;/b&gt;.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can read this article to read more about &lt;b&gt;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/02/what-is-webdriver-in-selenium.html&quot; target=&quot;_blank&quot;&gt;WebDriver in Selenium&lt;/a&gt;&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;22. How do you launch different browsers in Selenium WebDriver?&lt;/h3&gt;&lt;div&gt;I am using the browser-specific driver executable to launch the browser in Selenium test. I am using&amp;nbsp;Chromedriver to run tests in Google Chrome browser,&amp;nbsp;GeckoDriver for Mozilla Firefox browser, and&amp;nbsp;EdgeDriver to launch tests in Edge browser. Here is a detailed guide on how to download and configure&amp;nbsp;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/02/chrome-driver-download-for-selenium.html&quot; target=&quot;_blank&quot;&gt;Chromedriver&lt;/a&gt;,&amp;nbsp;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/02/how-to-download-geckodriver-for-firefox-in-selenium.html&quot; target=&quot;_blank&quot;&gt;GeckoDriver&lt;/a&gt;, and &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/edge-driver-download-for-selenium.html&quot;&gt;EdgeDriver&lt;/a&gt;&amp;nbsp;to use them in Selenium WebDriver.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here are the examples to launch different browsers in Selenium WebDriver test.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example to launch Chrome browser in Selenium&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span class=&quot;hljs-type&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;WebDriver&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;driver&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hljs-title class_&quot;&gt;ChromeDriver&lt;/span&gt;();
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.get(&lt;span class=&quot;hljs-string&quot;&gt;&quot;https://example.com&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;b&gt;Example to launch Firefox browser in Selenium&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span class=&quot;hljs-type&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;WebDriver&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;driver&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hljs-title class_&quot;&gt;FirefoxDriver&lt;/span&gt;();
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.get(&lt;span class=&quot;hljs-string&quot;&gt;&quot;https://example.com&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example to launch Edge browser in Selenium&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span class=&quot;hljs-type&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;WebDriver&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;driver&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hljs-title class_&quot;&gt;EdgeDriver&lt;/span&gt;();
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.get(&lt;span class=&quot;hljs-string&quot;&gt;&quot;https://example.com&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example to launch Safari browser in Selenium&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span class=&quot;hljs-type&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;WebDriver&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;driver&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hljs-title class_&quot;&gt;SafariDriver&lt;/span&gt;();
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.get(&lt;span class=&quot;hljs-string&quot;&gt;&quot;https://example.com&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;23. What is the difference between WebDriver and RemoteWebDriver?&lt;/h3&gt;&lt;div&gt;WebDriver is an interface in Selenium that allows communication directly with browsers. You can use&amp;nbsp;browser-specific drivers like ChromeDriver, GeckoDriver, or EdgeDriver, to execute commands on browsers in the local system.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;On the other hand,&amp;nbsp;RemoteWebDriver is a class that enables running Selenium tests on a remote machine.&amp;nbsp;It communicates with the remote browser using the W3C WebDriver Protocol (previously JSON Wire Protocol in older Selenium versions). Generally, we use&amp;nbsp;RemoteWebDriver to perform distributed testing, Selenium Grid, and cloud-based automation on platforms like BrowserStack and Sauce Labs.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Key Differences:&lt;/h4&gt;&lt;div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Execution Location&lt;/b&gt;:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;WebDriver executes Selenium tests on the local machine.&lt;/li&gt;&lt;li&gt;RemoteWebDriver runs tests remotely on another machine or cloud service.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Communication Protocol&lt;/b&gt;:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;WebDriver directly interacts with the browser drivers.&lt;/li&gt;&lt;li&gt;RemoteWebDriver executes Selenium commands using the W3C WebDriver Protocol over HTTP.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Use Case&lt;/b&gt;:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;WebDriver is best for local automation on a single browser instance.&lt;/li&gt;&lt;li&gt;You can use RemoteWebDriver to perform parallel execution across multiple machines in Selenium Grid or cloud testing services.&lt;/li&gt;&lt;/ul&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Example of WebDriver (Local Execution)&lt;/h4&gt;&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span class=&quot;hljs-type&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;WebDriver&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;driver&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hljs-title class_&quot;&gt;ChromeDriver&lt;/span&gt;();
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.get(&lt;span class=&quot;hljs-string&quot;&gt;&quot;https://example.com&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Example of RemoteWebDriver (Remote Execution)&lt;/h4&gt;&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span class=&quot;hljs-type&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;URL&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;remoteUrl&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hljs-title class_&quot;&gt;URL&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot;&gt;&quot;http://192.168.1.100:4444&quot;&lt;/span&gt;); &lt;span class=&quot;hljs-comment&quot;&gt;// Selenium Grid URL&lt;/span&gt;
&lt;span class=&quot;hljs-type&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;ChromeOptions&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;options&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hljs-title class_&quot;&gt;ChromeOptions&lt;/span&gt;(); &lt;span class=&quot;hljs-comment&quot;&gt;// Use browser options instead of DesiredCapabilities&lt;/span&gt;

&lt;span class=&quot;hljs-type&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;WebDriver&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;driver&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hljs-title class_&quot;&gt;RemoteWebDriver&lt;/span&gt;(remoteUrl, options);
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.get(&lt;span class=&quot;hljs-string&quot;&gt;&quot;https://example.com&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;24. How do you maximize a browser window in Selenium?&lt;/h3&gt;&lt;div&gt;In Selenium WebDriver, there are two ways to maximize window size. 1) You can use the maximize_window() method, and 2) You can use the setSize() method to manually set the maximized size as per your screen size. If you are using Headless Browsers, you can use&amp;nbsp;addArguments(&quot;--start-maximized&quot;) to maximize window size.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Let&#39;s see examples&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example of Maximizing window using&amp;nbsp;maximize_window()&amp;nbsp;method&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;// Set up the WebDriver (Make sure ChromeDriver path is set in system properties)
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;WebDriver driver = new ChromeDriver();

&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;// Open a website
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.get(&quot;https://www.example.com&quot;);

&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;// Maximize the browser window
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.manage().window().maximize();

&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;// Perform any test actions...

&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;// Close the browser
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.quit();
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here,&amp;nbsp;driver.manage().window().maximize(); syntax will maximize the window.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example of Maximizing window using setSize() method&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;WebDriver driver = new ChromeDriver();        
       driver.manage().window().setSize(new Dimension(1200, 800));&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If your screen size is 1200 x 800, then you can use the .setSize() method to maximize the window.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Example of Maximizing window in&amp;nbsp;Headless Browsers using addArguments(&quot;--start-maximized&quot;)&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;WebDriver driver;
	FirefoxOptions options=new FirefoxOptions();
	//To open  browser in Headeless mode.
	options.addArguments(&quot;--headless&quot;);	
	//To open headless browser maximized.
	options.addArguments(&quot;--start-maximized&quot;);
	driver = new FirefoxDriver(options);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The above example explains how to start a headless browser maximized.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Tips&lt;/b&gt;: You should run&amp;nbsp;Selenium tests in a full-screen environment to prevent UI interaction issues.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;25. How do you take a screenshot in Selenium WebDriver?&lt;/h3&gt;&lt;div&gt;We can use the TakesScreenshot interface to capture a screenshot while running the Selenium test.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example to take a Screenshot and Save as a File in Selenium&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;package com.secondpr;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;

public class takeScreenShot {

	public static void main(String[] args) {
	// Set up WebDriver
        WebDriver driver = new ChromeDriver();

        try {
            // Open a website
            driver.get(&quot;https://www.example.com&quot;);

            // Take a screenshot
            TakesScreenshot ts = (TakesScreenshot) driver;
            File source = ts.getScreenshotAs(OutputType.FILE);

            // Define destination path
            File destination = new File(&quot;D:\\homePageScreenshot.png&quot;);

            // Copy file to the destination
            FileUtils.copyFile(source, destination);

            System.out.println(&quot;Screenshot saved successfully!&quot;);
        } catch (IOException e) {
            System.out.println(&quot;Error while saving screenshot: &quot; + e.getMessage());
        } finally {
            // Close the browser
            driver.quit();
        }
	}
}&lt;/span&gt;&lt;span style=&quot;font-family: arial; font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;div&gt;&lt;b&gt;Note&lt;/b&gt;: You need to add external binary jars of&amp;nbsp;commons-io. You can download the latest jars from the &lt;a href=&quot;https://commons.apache.org/io/download_io.cgi&quot; target=&quot;_blank&quot;&gt;Apache Commons IO Download&lt;/a&gt; page.&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;26. How do you get the title of a webpage in Selenium?&lt;/h3&gt;&lt;div&gt;&lt;div&gt;In Selenium WebDriver, you can get the title of a webpage using the getTitle() method.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example to get webpage title:&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;div style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; font-size: medium; white-space: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;// Get and print the title of the webpage&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; font-size: medium; white-space: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;String pageTitle = driver.getTitle();&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; font-size: medium; white-space: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;System.out.println(&quot;Page Title: &quot; + pageTitle);&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;Here,&amp;nbsp;driver.getTitle(); retrieves the title of the current webpage. It is useful to validate if the correct page is loaded&amp;nbsp;during automation testing. Generally, this method is used to&amp;nbsp;&lt;span style=&quot;box-sizing: border-box; margin: 0px; padding: 0px;&quot;&gt;&lt;strong&gt;assert&lt;/strong&gt;&lt;/span&gt;&amp;nbsp;the expected title in test cases.&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;27. How do you get the current URL of a webpage?&lt;/h3&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;In Selenium WebDriver, you can use the getCurrentUrl() method to get the current URL of a webpage.&lt;/p&gt;&lt;div&gt;&lt;b&gt;Example to get current URL of WebPage:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 660.328px;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;div style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; font-size: medium; white-space: normal;&quot;&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;// Get and print the current URL&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; font-size: medium; white-space: normal;&quot;&gt;&lt;span class=&quot;hljs-type&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;String&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;currentURL&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; driver.getCurrentUrl();&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; font-size: medium; white-space: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;System.out.println(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Current URL: &quot;&lt;/span&gt; + currentURL);&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;In the above example, driver.getCurrentUrl() method will return the current URL of the webpage. You can use it to validate or assert that the correct page is loaded.&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;28. How do you handle cookies in Selenium WebDriver?&lt;/h3&gt;&lt;div&gt;In Selenium WebDriver, you can use getCookies(), addCookie(),&amp;nbsp;getCookieNamed(), deleteCookieNamed(), and&amp;nbsp;deleteAllCookies() methods to&amp;nbsp;add, retrieve, delete, and clear cookies.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;An example to manage cookies&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;package com.secondpr;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.Cookie;
import java.util.Set;

public class manageCookies {

	public static void main(String[] args) {
		
		WebDriver driver = new ChromeDriver();

        // Open a website
        driver.get(&quot;https://only-testing-blog.blogspot.com/&quot;);

        // 1. Get all cookies
        Set&amp;lt;Cookie&amp;gt; allCookies = driver.manage().getCookies();
        System.out.println(&quot;All Cookies: &quot; + allCookies);

        // 2. Get a specific cookie by name
        Cookie specificCookie = driver.manage().getCookieNamed(&quot;session_id&quot;);
        System.out.println(&quot;Session Cookie: &quot; + specificCookie);

        // 3. Add a new cookie
        Cookie newCookie = new Cookie(&quot;test_cookie&quot;, &quot;123456&quot;);
        driver.manage().addCookie(newCookie);
        System.out.println(&quot;Added new cookie: &quot; + newCookie);
        
        // 4. Delete a specific cookie
        driver.manage().deleteCookieNamed(&quot;test_cookie&quot;);
        System.out.println(&quot;Deleted &#39;test_cookie&#39;&quot;);

        // 5. Delete all cookies
        driver.manage().deleteAllCookies();
        System.out.println(&quot;All cookies deleted&quot;);

        // Close the browser
        driver.quit();	}

}&lt;/span&gt;&lt;span style=&quot;font-family: arial; font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;strong data-end=&quot;1565&quot; data-start=&quot;1523&quot;&gt;Explanation of Cookie Handling Methods&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;driver.manage().getCookies(); → Fetches all cookies.&lt;/li&gt;&lt;li&gt;driver.manage().getCookieNamed(&quot;cookie_name&quot;); → Retrieves a specific cookie by name.&lt;/li&gt;&lt;li&gt;driver.manage().addCookie(new Cookie(&quot;name&quot;, &quot;value&quot;)); → Adds a new cookie.&lt;/li&gt;&lt;li&gt;driver.manage().deleteCookieNamed(&quot;cookie_name&quot;); → Deletes a specific cookie.&lt;/li&gt;&lt;li&gt;driver.manage().deleteAllCookies(); → Clears all cookies.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Why Handle Cookies in Selenium?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;To maintain user sessions without logging in repeatedly.&lt;/li&gt;&lt;li&gt;Test authentication by manually adding session cookies.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;29. How do you delete all cookies using Selenium?&lt;/h3&gt;&lt;div&gt;You can use the deleteAllCookies() method for it as described in the example of the previous question&#39;s answer.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;30. What is the difference between close() and quit()?&lt;/h3&gt;&lt;div&gt;Here are the Main differences between close() and quit() methods.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Functionality&lt;/b&gt;:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;close(): Closes the current browser window.&lt;/li&gt;&lt;li&gt;quit(): Closes all browser windows opened by Selenium.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Scope&lt;/b&gt;:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;close(): Only the active browser window is closed.&lt;/li&gt;&lt;li&gt;quit(): All browser sessions initiated by WebDriver are closed.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;WebDriver Instance&lt;/b&gt;:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;close(): WebDriver session remains active if multiple windows exist.&lt;/li&gt;&lt;li&gt;quit(): WebDriver session is terminated completely.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Usage&lt;/b&gt;:&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;close(): Used when handling multiple windows/tabs and only one needs to be closed.&lt;/li&gt;&lt;li&gt;quit():&amp;nbsp;Used when the entire test execution is complete and no further actions are needed.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div&gt;&lt;b&gt;Tips&lt;/b&gt;: You can use close()&amp;nbsp;when you want to close only the current window but keep WebDriver running. But you can use the quit() method to close all browser windows and end the WebDriver session.&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Best Practice&lt;/b&gt;: Always use quit() at the end of the test execution to avoid memory leaks!&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;31. How do you handle JavaScript alerts in Selenium?&lt;/h3&gt;&lt;div&gt;There are three types of JavaScript alerts:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Simple Alert → Only has an &quot;OK&quot; button.&lt;/li&gt;&lt;li&gt;Confirmation Alert → Has &quot;OK&quot; and &quot;Cancel&quot; buttons.&lt;/li&gt;&lt;li&gt;Prompt Alert → Has a text box, along with &quot;OK&quot; and &quot;Cancel&quot; buttons.&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here is an explanation on how to manage alerts in Selenium.&lt;/p&gt;&lt;div&gt;&lt;b&gt;Switch to alert:&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;You can use the given syntax to switch Selenium test execution on alert.&lt;/div&gt;&lt;div&gt;Alert alert = driver.switchTo().alert();&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Accepting an Alert (OK Button)&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;alert.accept(); // Clicks &quot;OK&quot; button.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Dismissing an Alert (Cancel Button)&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;alert.dismiss(); // Clicks &quot;Cancel&quot; button.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;b&gt;Getting the Alert Message&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;String alertText = alert.getText();&lt;/div&gt;&lt;div&gt;System.out.println(&quot;Alert Message: &quot; + alertText);&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Handling Prompt Alert (Entering Text)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;alert.sendKeys(&quot;Test Input&quot;); // Enter text in the alert box&lt;/div&gt;&lt;div&gt;alert.accept(); // Clicks &quot;OK&quot; button.&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Handling alerts is important for pop-ups, form validations, and confirmations in test automation.&lt;/p&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;32. How do you perform drag and drop in Selenium?&lt;/h3&gt;&lt;div&gt;In Selenium, you can use the Actions class to perform drag and drop actions.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Here is an example of drag and drop&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;package com.secondpr;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;

public class dragDrop {

	public static void main(String[] args) {
	// Set up WebDriver
        WebDriver driver = new ChromeDriver();

        // Open a website with drag-and-drop functionality
        driver.get(&quot;https://jqueryui.com/droppable/&quot;);

        // Switch to iframe if the elements are inside one
        driver.switchTo().frame(0);

        // Locate source (element to be dragged) and target (element where to drop)
        WebElement source = driver.findElement(By.id(&quot;draggable&quot;));
        WebElement target = driver.findElement(By.id(&quot;droppable&quot;));

        try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        // Perform drag and drop
        Actions actions = new Actions(driver);
        actions.dragAndDrop(source, target).perform();
        
        try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

        System.out.println(&quot;Drag and drop successful!&quot;);

        // Close browser
        driver.quit();
	}
}
&lt;/span&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;The above example will drag an element from the source and drop it on the destination. Try it.&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Other Ways to Perform Drag and Drop&lt;/b&gt;&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Using clickAndHold(), moveToElement(), and release()&lt;/b&gt;. You can use this method when&amp;nbsp;dragAndDrop() doesn’t work due to JavaScript interference.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;:&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;actions.clickAndHold(source)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;.moveToElement(target)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&amp;nbsp;.release()&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;.build()&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;.perform();&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Using moveByOffset() (Dragging to Specific Coordinates).&lt;span style=&quot;font-weight: normal;&quot;&gt; You can use it when&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;drop location is dynamic or doesn’t have a unique identifier.&lt;/span&gt;&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;&lt;/p&gt;&lt;div&gt;&lt;div&gt;actions.clickAndHold(source)&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;.moveByOffset(100, 50) // Move by X and Y offset&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;.release()&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;.perform();&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Tips&lt;/b&gt;:&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Use dragAndDrop(source, target).perform(); for standard cases.&lt;/li&gt;&lt;li&gt;Use clickAndHold(), moveToElement(), and release() if dragAndDrop() doesn’t work.&lt;/li&gt;&lt;li&gt;Use moveByOffset(x, y) for pixel-based movement.&lt;/li&gt;&lt;li&gt;Always switch to the iframe first if elements are inside it.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;You can use&amp;nbsp;drag and drop for&amp;nbsp;file uploads, game testing, and UI interactions.&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;33. How do you simulate keyboard and mouse actions in Selenium?&lt;/h3&gt;&lt;div&gt;You can use&amp;nbsp;Actions and Robot classes to simulate keyboard and mouse actions.&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Using Actions Class (Recommended)&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Mouse Actions Example&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;Actions&lt;span style=&quot;background-color: transparent;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hljs-variable&quot; style=&quot;background-color: transparent;&quot;&gt;actions&lt;/span&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hljs-operator&quot; style=&quot;background-color: transparent;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;background-color: transparent;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hljs-title class_&quot; style=&quot;background-color: transparent;&quot;&gt;Actions&lt;/span&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;(driver);
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;actions.moveToElement(element).perform();  &lt;/span&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;background-color: transparent;&quot;&gt;// Hover  &lt;/span&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;actions.contextClick(element).perform();   &lt;/span&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;background-color: transparent;&quot;&gt;// Right-click  &lt;/span&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;actions.doubleClick(element).perform();    &lt;/span&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;background-color: transparent;&quot;&gt;// Double-click&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Keyboard Actions&lt;/h4&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;actions.sendKeys(Keys.ENTER).perform();  &lt;span class=&quot;hljs-comment&quot;&gt;// Press Enter  &lt;/span&gt;
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;actions.keyDown(Keys.SHIFT).sendKeys(&lt;span class=&quot;hljs-string&quot;&gt;&quot;text&quot;&lt;/span&gt;).keyUp(Keys.SHIFT).perform();  &lt;span class=&quot;hljs-comment&quot;&gt;// Type in uppercase  &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Using Robot Class (For Advanced Interactions)&lt;/b&gt;&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Keyboard Input&lt;/b&gt;&lt;/p&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span class=&quot;hljs-type&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;Robot&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;robot&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hljs-title class_&quot;&gt;Robot&lt;/span&gt;();
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;robot.keyPress(KeyEvent.VK_ENTER);
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;robot.keyRelease(KeyEvent.VK_ENTER);&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Mouse Actions&lt;/b&gt;&lt;/p&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;robot.mouseMove(&lt;span class=&quot;hljs-number&quot;&gt;500&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;300&lt;/span&gt;);  &lt;span class=&quot;hljs-comment&quot;&gt;// Move mouse  &lt;/span&gt;
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);  &lt;span class=&quot;hljs-comment&quot;&gt;// Left-click  &lt;/span&gt;
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Tips&lt;/b&gt;:&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can use the Actions class for web-based interactions, i.e. hover, right-click, drag &amp;amp; drop, keyboard inputs, and the Robot class for system-level interactions, i.e.. file uploads, screenshots, handling OS pop-ups.&amp;nbsp;Actions class is preferred for browser-based automation, while Robot is used when Actions doesn&#39;t work.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;34. What is the Actions class in Selenium?&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;The Actions class in Selenium performs advanced user interactions, such as mouse hover, right-click, double-click, drag-and-drop, and keyboard actions. It helps automate complex gestures that require a combination of keyboard and mouse events.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Its key features include mouse actions, keyboard inputs, and composite gestures for seamless automation.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;35. What is the difference between Action and Actions class?&lt;/h3&gt;&lt;div&gt;Main differences between&amp;nbsp;Action and Actions class are:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Type&lt;/b&gt;:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Action class&lt;/b&gt;: It is an Interface.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Actions class&lt;/b&gt;: It is a Class.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Purpose&lt;/b&gt;:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Action&amp;nbsp;class&lt;/b&gt;: It represents a single action.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Actions&amp;nbsp;class&lt;/b&gt;: It is used to build and perform a series of actions.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Usage&lt;/b&gt;:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Action&amp;nbsp;class&lt;/b&gt;: It stores one action at a time.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Actions&amp;nbsp;class&lt;/b&gt;: It has a chain of multiple actions together.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div&gt;&lt;b&gt;Here is an example of the Action interface and the Actions class&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;// Using Actions class to build and perform actions
Actions actions = new Actions(driver);
actions.moveToElement(element).click().perform(); // Hover and click

// Using Action interface to store an action
Action action = actions.moveToElement(element).click().build();
action.perform(); // Perform stored action&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;36. How do you simulate right-click in Selenium?&lt;/h3&gt;&lt;div&gt;We can simulate a right-click in Selenium using the contextClick() method from the Actions class.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;:&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;WebElement element = driver.findElement(By.id(&quot;rightClickElement&quot;));
        Actions actions = new Actions(driver);
        actions.contextClick(element).perform();  // Right-click action&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;37. How do you simulate double-click in Selenium?&lt;/h3&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can perform a double-click in Selenium using the doubleClick() method from the Actions class.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here is an example:&lt;/p&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;WebElement element = driver.findElement(By.id(&quot;doubleClickElement&quot;));

        Actions actions = new Actions(driver);
        actions.doubleClick(element).perform();  // Double-click action
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;38. How do you handle frames and iframes in Selenium?&lt;/h3&gt;&lt;div&gt;&lt;div&gt;In Selenium, you can switch to a frame or iframe using the switchTo().frame() method. You can switch to frame using Index, name, or ID, or a WebElement.&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here are examples using different methods:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example of switch to frame by Index:&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.switchTo().frame(0);  // Switch to the first frame
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example of switch to frame by Name or ID:&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.switchTo().frame(&quot;frameName&quot;);  // Switch using frame name or ID
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example of switch to frame by WebElement:&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;WebElement frameElement = driver.findElement(By.tagName(&quot;iframe&quot;));
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.switchTo().frame(frameElement);  // Switch using WebElement
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example of Switch Back to Main Page:&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;driver.switchTo().defaultContent();  // Exit from frame to main content
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;39. How do you work with checkboxes and radio buttons in Selenium?&lt;/h3&gt;&lt;div&gt;&lt;div&gt;In Selenium, you can interact with checkboxes and radio buttons using the click(), isSelected(), and getAttribute() methods.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here is an example of&amp;nbsp;Selecting a Checkbox and&amp;nbsp;Radio Button.&lt;/p&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;WebElement checkbox = driver.findElement(By.id(&quot;subscribe&quot;));
checkbox.click();  // Click to select

// Verify if checkbox is selected
if (checkbox.isSelected()) {
    System.out.println(&quot;Checkbox is selected.&quot;);
}

WebElement radioButton = driver.findElement(By.id(&quot;genderMale&quot;));
radioButton.click();  // Select radio button&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;40. How do you handle hidden elements in Selenium?&lt;/h3&gt;&lt;div&gt;You can not interact with hidden elements directly in Selenium. But, you can use the following methods to interact with them.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;JavaScript Executor (Force Click)&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement hiddenElement = driver.findElement(By.id(&quot;hiddenButton&quot;));
js.executeScript(&quot;arguments[0].click();&quot;, hiddenElement);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Checking Visibility Before Action&lt;/b&gt;&lt;/p&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;WebElement element = driver.findElement(By.id(&quot;hiddenElement&quot;));
if (element.isDisplayed()) {
    element.click();
} else {
    System.out.println(&quot;Element is hidden&quot;);
}&lt;/code&gt;&lt;/pre&gt;&lt;/b&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Using Actions Class (For Hover to Reveal Elements)&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;Actions actions = new Actions(driver);
WebElement menu = driver.findElement(By.id(&quot;menu&quot;));
actions.moveToElement(menu).perform();  // Hover to make hidden element visible&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Selenium Automation Framework Questions&lt;/h2&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;41. What is a Selenium Framework?&lt;/h3&gt;&lt;div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Types of Selenium Frameworks:&lt;/h4&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Data-Driven Framework&lt;/b&gt; → Uses external data sources (Excel, CSV). You can use it to&amp;nbsp;test multiple inputs without modifying scripts.&lt;/p&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;String data = excelSheet.getCellData(&quot;TestData.xlsx&quot;, &quot;Sheet1&quot;, 1, 1);
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Keyword-Driven Framework&lt;/b&gt; → Uses predefined keywords for test execution. It helps you to separate test logic from the script.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;executeAction(&quot;Click&quot;, &quot;loginButton&quot;);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Hybrid Framework&lt;/b&gt; → Combines Data-Driven + Keyword-Driven approaches. It works well for large-scale automation projects.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Page Object Model (POM)&lt;/b&gt; → Organizes elements and actions into separate classes. It helps to&amp;nbsp;improve code reusability &amp;amp; readability.&lt;/p&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;LoginPage login = new LoginPage(driver);
login.enterUsername(&quot;user&quot;);
login.clickLogin();&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;42. What are the different types of Selenium frameworks?&lt;/h3&gt;&lt;div&gt;Frameworks are already mentioned in the previous answer.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;43. What is the Page Object Model (POM) in Selenium?&lt;/h3&gt;&lt;div&gt;The Page Object Model (POM) is a design pattern that helps organize Selenium test scripts by separating UI elements and test logic into different classes. It enhances the usability, maintenance, and readability of test scripts.&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Key Advantages of POM:&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Helps to reduce duplicate code.&lt;/li&gt;&lt;li&gt;Enhances test script readability.&lt;/li&gt;&lt;li&gt;Easy to maintain test scripts when UI changes.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;b&gt;Example of POM&lt;/b&gt;:&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Create a Page Class (LoginPage.java)&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;

public class LoginPage {
    WebDriver driver;

    // Locators
    By username = By.id(&quot;user&quot;);
    By password = By.id(&quot;pass&quot;);
    By loginButton = By.id(&quot;login&quot;);

    // Constructor
    public LoginPage(WebDriver driver) {
        this.driver = driver;
    }

    // Methods to interact with elements
    public void enterUsername(String user) {
        driver.findElement(username).sendKeys(user);
    }

    public void enterPassword(String pass) {
        driver.findElement(password).sendKeys(pass);
    }

    public void clickLogin() {
        driver.findElement(loginButton).click();
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Use the Page Class in a Test (LoginTest.java)&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;WebDriver driver = new ChromeDriver();
driver.get(&quot;https://example.com&quot;);

LoginPage login = new LoginPage(driver);
login.enterUsername(&quot;testUser&quot;);
login.enterPassword(&quot;testPass&quot;);
login.clickLogin();&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;44. What are the advantages of using POM?&lt;/h3&gt;&lt;div&gt;Main advantages of POM are as below.&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Better Code Maintainability&lt;/b&gt; – You need to update only the page classes, If there is any change in the UI. Do not need to update all test cases.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Increased Reusability&lt;/b&gt; – You can reuse common UI actions like login, search across multiple tests.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Improved Readability&lt;/b&gt; – Test scripts are cleaner and easier to understand.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Separation of Concerns&lt;/b&gt; – Keeps test logic separate from UI element locators.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Reduces Code Duplication&lt;/b&gt; – No need to define locators in multiple places.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;45. What is Page Factory in Selenium?&lt;/h3&gt;&lt;div&gt;&lt;div&gt;Page Factory is an optimized way to implement the Page Object Model (POM) in Selenium. It simplifies element initialization using the @FindBy annotation and PageFactory.initElements(), which makes test scripts cleaner and more efficient.&lt;/div&gt;&lt;p&gt;&lt;b&gt;Key Benefits of&amp;nbsp;Page Factory&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Automatic element initialization using @FindBy.&lt;/li&gt;&lt;li&gt;Improves readability &amp;amp; maintainability of test scripts.&lt;/li&gt;&lt;li&gt;Faster execution due to lazy loading of elements.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example of Page Factory Implementation&lt;/b&gt;&lt;/h4&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Define Page Class (LoginPage.java)&lt;/b&gt;&lt;/p&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class LoginPage {
    WebDriver driver;

    // Locate elements using @FindBy annotation
    @FindBy(id = &quot;user&quot;) 
    WebElement username;

    @FindBy(id = &quot;pass&quot;) 
    WebElement password;

    @FindBy(id = &quot;login&quot;) 
    WebElement loginButton;

    // Constructor to initialize Page Factory
    public LoginPage(WebDriver driver) {
        this.driver = driver;
        PageFactory.initElements(driver, this);
    }

    // Methods to interact with elements
    public void enterUsername(String user) {
        username.sendKeys(user);
    }

    public void enterPassword(String pass) {
        password.sendKeys(pass);
    }

    public void clickLogin() {
        loginButton.click();
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Use Page Factory in Test (LoginTest.java)&lt;/b&gt;&lt;/p&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;WebDriver driver = new ChromeDriver();
driver.get(&quot;https://example.com&quot;);

LoginPage login = new LoginPage(driver);
login.enterUsername(&quot;testUser&quot;);
login.enterPassword(&quot;testPass&quot;);
login.clickLogin();&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;46. How is Page Factory different from POM?&lt;/h3&gt;&lt;div&gt;Key differences between page object model and page factory are as below.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Element Initialization&lt;/b&gt;:&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;POM: Uses driver.findElement() manually.&lt;/li&gt;&lt;li&gt;Page Factory: Uses @FindBy annotation with PageFactory.initElements()&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Code Readability&lt;/b&gt;:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;POM: Requires more lines of code.&lt;/li&gt;&lt;li&gt;Page Factory: Cleaner and more concise&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Performance&lt;/b&gt;:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;POM: Loads elements immediately.&lt;/li&gt;&lt;li&gt;Page Factory:&amp;nbsp;Uses lazy initialization, loading elements only when needed.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Maintainability&lt;/b&gt;:&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;POM:&amp;nbsp;Requires explicit element declaration.&lt;/li&gt;&lt;li&gt;Page Factory:&amp;nbsp;Automatically initializes elements, making maintenance easier.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;47. How do you handle dynamic elements in Selenium?&lt;/h3&gt;&lt;div&gt;&lt;div&gt;Dynamic elements have changing attributes (like IDs or XPaths) on every page load. You can handle them using:&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Using Dynamic XPath&lt;/h4&gt;&lt;div&gt;Identify elements with partial attributes or text.&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;WebElement element = driver.findElement(By.xpath(&quot;//*[contains(@id, &#39;dynamicPart&#39;)]&quot;));&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Using CSS Selectors with Wildcards&lt;/h4&gt;&lt;div&gt;Target elements with starts-with (^), ends-with ($), or contains (*) attributes.&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;WebElement element = driver.findElement(By.cssSelector(&quot;[id^=&#39;start&#39;]&quot;));&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Using Explicit Wait&lt;/h4&gt;&lt;div&gt;Wait until the element is visible or clickable.&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(&quot;dynamicElement&quot;)));&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Using JavaScript Executor (If Element is Not Detected)&lt;/h4&gt;&lt;/div&gt;&lt;div&gt;Fetch the element using JavaScript.&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement element = (WebElement) js.executeScript(&quot;return document.querySelector(&#39;[id^=\&quot;dynamic\&quot;]&#39;);&quot;);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;48. What is TestNG?&lt;/h3&gt;&lt;div&gt;Full form of TestNG is&amp;nbsp;Test Next Generation. It is a powerful testing framework in Java. It is designed to simplify test execution and reporting. It is widely used in Selenium automation for managing test cases efficiently.&lt;/div&gt;&lt;p&gt;&lt;b&gt;Key Features of TestNG&lt;/b&gt;:&lt;/p&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Annotations&lt;/b&gt;: We can use annotations like @Test, @BeforeMethod, @AfterMethod for structured testing.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Parallel Test Execution&lt;/b&gt;: Allows to run multiple tests simultaneously.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Assertions&lt;/b&gt;: Has great assertions for result validation.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Report Generation&lt;/b&gt;: Can generate&amp;nbsp;detailed test results.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;49. What are the advantages of using TestNG?&lt;/h3&gt;&lt;div&gt;Here are the advantages of using TestNG in Selenium.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Annotations for Better Test Structure&lt;/b&gt; → Uses @Test, @BeforeMethod, @AfterMethod for organized test execution.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Parallel Test Execution&lt;/b&gt; → Runs multiple tests at the same time, reducing execution time.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Built-in Reporting&lt;/b&gt; → Generates detailed HTML test reports automatically.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Data-Driven Testing with @DataProvider&lt;/b&gt; → Enables testing with multiple data sets.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Flexible Test Execution with XML&lt;/b&gt; → Run specific tests by modifying the testng.xml file.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;:&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;@DataProvider(name = &quot;loginData&quot;)
public Object[][] getData() { return new Object[][] { {&quot;user1&quot;, &quot;pass1&quot;}, {&quot;user2&quot;, &quot;pass2&quot;} }; }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;50. What is the difference between JUnit and TestNG?&lt;/h3&gt;&lt;div&gt;Here are the differences of&amp;nbsp;JUnit and TestNG features.&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;JUnit&lt;/h4&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Annotations&lt;/b&gt;: You can use @Test, @Before, @After annotations.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Dependency Support:&lt;/b&gt;&amp;nbsp;No built-in support for test dependencies&lt;/li&gt;&lt;li&gt;&lt;b&gt;Parallel Execution&lt;/b&gt;: Not supported.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Parameterized Tests&lt;/b&gt;: Uses @RunWith(Parameterized.class).&lt;/li&gt;&lt;li&gt;&lt;b&gt;Reporting&lt;/b&gt;:&amp;nbsp;Basic reporting.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Test Execution Control&lt;/b&gt;:&amp;nbsp;Runs tests alphabetically.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;TestNG&lt;/h4&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Annotations&lt;/b&gt;:&amp;nbsp;More powerful annotations that include @BeforeMethod, @AfterMethod. @DataProvider&lt;/li&gt;&lt;li&gt;&lt;b&gt;Dependency Support:&lt;/b&gt;&amp;nbsp;Supports dependencies using dependsOnMethods.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Parallel Execution&lt;/b&gt;:&amp;nbsp;Supported using testng.xml.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Parameterized Tests&lt;/b&gt;: Uses @DataProvider (more flexible).&lt;/li&gt;&lt;li&gt;&lt;b&gt;Reporting&lt;/b&gt;:&amp;nbsp;Generates detailed HTML reports.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Test Execution Control&lt;/b&gt;:&amp;nbsp;Runs based on priority using priority attribute.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;51. What is an annotation in TestNG?&lt;/h3&gt;&lt;div&gt;&lt;div&gt;In TestNG, annotations are special markers (starting with @) that control the test execution flow. They define setup, teardown, test execution, and dependencies in a structured way.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here is the list of common TestNG annotations with their usage.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;@Test&lt;/b&gt;: Marks a method as a test case.&lt;/li&gt;&lt;li&gt;&lt;b&gt;@BeforeMethod&lt;/b&gt;:&amp;nbsp;Runs before each test method.&lt;/li&gt;&lt;li&gt;&lt;b&gt;@AfterMethod&lt;/b&gt;:&amp;nbsp;Runs after each test method.&lt;/li&gt;&lt;li&gt;&lt;b&gt;@BeforeClass&lt;/b&gt;:&amp;nbsp;Runs once before all test methods in a class.&lt;/li&gt;&lt;li&gt;&lt;b&gt;@AfterClass&lt;/b&gt;:&amp;nbsp;Runs once after all test methods in a class.&lt;/li&gt;&lt;li&gt;&lt;b&gt;@DataProvider&lt;/b&gt;:&amp;nbsp;Provides test data for data-driven testing.&lt;/li&gt;&lt;li&gt;&lt;b&gt;@Parameters&lt;/b&gt;: Passes values from testng.xml to test cases.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;52. What is a DataProvider in TestNG?&lt;/h3&gt;&lt;div&gt;You can use&amp;nbsp;@DataProvider in TestNG to perform data-driven testing. It allows the test method to run multiple times with different data sets. It helps in executing parameterized tests efficiently.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here are key features:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;You can use it to run the same test with multiple inputs.&lt;/li&gt;&lt;li&gt;Eliminates hardcoded test data in test scripts.&lt;/li&gt;&lt;li&gt;Can fetch data from Excel, CSV, or databases.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;53. How do you use DataProvider to pass test data?&lt;/h3&gt;&lt;div&gt;To use&amp;nbsp;@DataProvider in Selenium test, follow the steps below.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Define a method with @DataProvider.&lt;/li&gt;&lt;li&gt;Return a 2D Object array containing test data.&lt;/li&gt;&lt;li&gt;Use @Test(dataProvider = &quot;providerName&quot;) to link the test with the DataProvider.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;Here is an example of how to pass test data using&amp;nbsp;DataProvider.&lt;/div&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Example: Passing Test Data Using DataProvider&lt;/h4&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;import org.testng.annotations.*;

public class DataProviderExample {

    // Step 1: Define DataProvider
    @DataProvider(name = &quot;loginData&quot;)
    public Object[][] getData() {
        return new Object[][] {
            {&quot;user1&quot;, &quot;pass1&quot;},
            {&quot;user2&quot;, &quot;pass2&quot;},
            {&quot;user3&quot;, &quot;pass3&quot;}
        };
    }

    // Step 2: Use DataProvider in Test
    @Test(dataProvider = &quot;loginData&quot;)
    public void testLogin(String username, String password) {
        System.out.println(&quot;Testing login with: &quot; + username + &quot; / &quot; + password);
        // Add Selenium code to perform login here
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;54. What is a TestNG XML file?&lt;/h3&gt;&lt;div&gt;A TestNG XML file (testng.xml) is a configuration file. It is useful to organize and execute multiple test cases&amp;nbsp;in a structured way. It allows:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;To run&amp;nbsp;multiple test classes together.&lt;/li&gt;&lt;li&gt;To group and prioritize test cases.&lt;/li&gt;&lt;li&gt;Parallel test execution.&lt;/li&gt;&lt;li&gt;To pass&amp;nbsp;parameters to test methods.&lt;/li&gt;&lt;/ul&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Example: Basic TestNG XML File (testng.xml)&lt;/h4&gt;&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&amp;lt;suite name=&quot;TestSuite&quot;&amp;gt;
    &amp;lt;test name=&quot;LoginTest&quot;&amp;gt;
        &amp;lt;classes&amp;gt;
            &amp;lt;class name=&quot;tests.LoginTest&quot;/&amp;gt;
        &amp;lt;/classes&amp;gt;
    &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;How to Run Tests Using TestNG XML?&lt;/h3&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Right click on the testng.xml file.&lt;/li&gt;&lt;li&gt;Select &quot;Run As → TestNG Suite&quot; in Eclipse.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;55. How do you run tests in parallel using TestNG?&lt;/h3&gt;&lt;div&gt;TestNG allows parallel execution to speed up test runs by running multiple tests simultaneously. You can configure it in the testng.xml file using the parallel attribute.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Steps to Run Tests in Parallel&lt;/b&gt;:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Set parallel=&quot;methods&quot; or parallel=&quot;classes&quot; in testng.xml.&lt;/li&gt;&lt;li&gt;Define thread-count to control how many threads run at the same time.&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example: Parallel Execution of Test Methods (testng.xml)&lt;/b&gt;&lt;/p&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&amp;lt;suite name=&quot;ParallelSuite&quot; parallel=&quot;methods&quot; thread-count=&quot;2&quot;&amp;gt;
    &amp;lt;test name=&quot;ParallelTest&quot;&amp;gt;
        &amp;lt;classes&amp;gt;
            &amp;lt;class name=&quot;tests.ParallelTest&quot;/&amp;gt;
        &amp;lt;/classes&amp;gt;
    &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Java Example: Parallel Test Execution&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;import org.testng.annotations.Test;

public class ParallelTest {
    
    @Test
    public void testOne() {
        System.out.println(&quot;Test One - &quot; + Thread.currentThread().getId());
    }

    @Test
    public void testTwo() {
        System.out.println(&quot;Test Two - &quot; + Thread.currentThread().getId());
    }
}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;56. What is the difference between soft assert and hard assert?&lt;/h3&gt;&lt;div&gt;Difference between&amp;nbsp;soft assert and hard assert is as below.&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Hard&amp;nbsp;Assert:&amp;nbsp;&lt;/h4&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Stops Execution?&lt;/b&gt;:&amp;nbsp;Yes, it stops execution once test fails and so&amp;nbsp;assertion fails.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Multiple Assertions?&lt;/b&gt;: Not possible, as execution stops on failure.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Best For?&lt;/b&gt;:&amp;nbsp;Critical validations like login success.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Soft Assert:&amp;nbsp;&lt;/h4&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Stops Execution?&lt;/b&gt;: Execution will continue even if&amp;nbsp;assertion fails.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Multiple Assertions?&lt;/b&gt;: Possible, as failures are collected and reported at the end.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Best For?&lt;/b&gt;:&amp;nbsp;Non-critical checks (e.g., UI element verification).&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;57. How do you generate reports in TestNG?&lt;/h3&gt;&lt;div&gt;TestNG has built-in features to generate HTML&amp;nbsp;and XML reports after test execution. However, you can use&amp;nbsp;IReporter or ITestListener to generate interactive&amp;nbsp;custom reports.&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Default TestNG Report (HTML &amp;amp; XML)&lt;/h4&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;TestNG creates a report in the test-output folder once you run the test.&lt;/li&gt;&lt;li&gt;You can open test-output/index.html file in a browser to view the report.&lt;/li&gt;&lt;/ul&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Generating Custom Reports Using IReporter&lt;/h4&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can implement IReporter to customize reports as below.&lt;/p&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;import org.testng.IReporter;
import org.testng.ISuite;
import org.testng.xml.XmlSuite;
import java.util.List;

public class CustomReport implements IReporter {
    public void generateReport(List&amp;lt;XmlSuite&amp;gt; xmlSuites, List&amp;lt;ISuite&amp;gt; suites, String outputDirectory) {
        System.out.println(&quot;Generating custom report...&quot;);
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Add to testng.xml:&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&amp;lt;listeners&amp;gt;
    &amp;lt;listener class-name=&quot;reports.CustomReport&quot;/&amp;gt;
&amp;lt;/listeners&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Using ITestListener for Custom Logs&lt;/h4&gt;&lt;p&gt;Capture test start, success, and failure logs.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;import org.testng.ITestListener;
import org.testng.ITestResult;

public class TestListener implements ITestListener {
    public void onTestSuccess(ITestResult result) {
        System.out.println(&quot;Test Passed: &quot; + result.getName());
    }
    
    public void onTestFailure(ITestResult result) {
        System.out.println(&quot;Test Failed: &quot; + result.getName());
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Add to testng.xml:&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&amp;lt;listeners&amp;gt;
    &amp;lt;listener class-name=&quot;listeners.TestListener&quot;/&amp;gt;
&amp;lt;/listeners&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;58. What is Maven and how does it help in Selenium automation?&lt;/h3&gt;&lt;div&gt;Maven is a build automation and dependency management tool for Java projects. You can use Maven to manage&amp;nbsp;project dependencies. Also, it is useful to build and run selenium test cases&amp;nbsp;efficiently.&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;How Maven Helps in Selenium Automation?&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Manages Dependencies Automatically&lt;/b&gt;:&amp;nbsp;No need to download JAR files manually.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Standard Project Structure:&lt;/b&gt;&amp;nbsp;It&amp;nbsp;follows a predefined structure. So it is easy to maintain a project.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Easier Test Execution&lt;/b&gt;: You can run tests using a simple command &quot;mvn test&quot;.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Integration with CI/CD&lt;/b&gt;: You can integrate it easily with&amp;nbsp;Jenkins, GitHub Actions, Azure DevOps for automation.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Parallel &amp;amp; Cross-Browser Testing&lt;/b&gt;: It is easy to&amp;nbsp;configure TestNG for parallel execution using Maven.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;59. What is a pom.xml file in Maven?&lt;/h3&gt;&lt;div&gt;The pom.xml (Project Object Model) file is the core configuration file in a Maven project. It defines:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Project details (name, version, description).&lt;/li&gt;&lt;li&gt;Dependencies (e.g., Selenium, TestNG).&lt;/li&gt;&lt;li&gt;Plugins (e.g., Maven Surefire for running tests).&lt;/li&gt;&lt;li&gt;Build and execution commands.&lt;/li&gt;&lt;/ul&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;How pom.xml Helps in Selenium?&lt;/h4&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Manages dependencies automatically:&lt;/b&gt;&amp;nbsp;No need to download JARs manually.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Easy test execution&lt;/b&gt;: Run tests using mvn test.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Integrates with CI/CD&lt;/b&gt;: Works with Jenkins, GitHub Actions, etc.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;60. How do you integrate Selenium with Maven?&lt;/h3&gt;&lt;div&gt;You can integrate Maven with Selenium to simplify&amp;nbsp;dependency management and test execution. You can follow these steps&amp;nbsp;to set up a Selenium Maven project easily.&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Steps to Integrate Selenium with Maven&lt;/h4&gt;&lt;div&gt;&lt;b&gt;Create a Maven Project&lt;/b&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;In Eclipse/IntelliJ:&amp;nbsp;File → New → Maven Project → Select Quickstart Archetype.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Add Selenium &amp;amp; TestNG Dependencies in pom.xml&lt;/b&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&amp;lt;dependencies&amp;gt;
    &amp;lt;!-- Selenium WebDriver --&amp;gt;
    &amp;lt;!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --&amp;gt;
	&amp;lt;dependency&amp;gt;
    		&amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
    		&amp;lt;artifactId&amp;gt;selenium-java&amp;lt;/artifactId&amp;gt;
    		&amp;lt;version&amp;gt;4.29.0&amp;lt;/version&amp;gt;
	&amp;lt;/dependency&amp;gt;


    &amp;lt;!-- TestNG --&amp;gt;
    &amp;lt;!-- https://mvnrepository.com/artifact/org.testng/testng --&amp;gt;
	&amp;lt;dependency&amp;gt;
    		&amp;lt;groupId&amp;gt;org.testng&amp;lt;/groupId&amp;gt;
    		&amp;lt;artifactId&amp;gt;testng&amp;lt;/artifactId&amp;gt;
    		&amp;lt;version&amp;gt;7.11.0&amp;lt;/version&amp;gt;
    		&amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt;
	&amp;lt;/dependency&amp;gt;

&amp;lt;/dependencies&amp;gt;
&lt;/span&gt;&lt;span style=&quot;font-family: arial; font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Write a Sample Selenium Test (Java)&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Create a test class in src/test/java&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class GoogleTest {
    @Test
    public void openGoogle() {
        WebDriver driver = new ChromeDriver();
        driver.get(&quot;https://www.google.com&quot;);
        System.out.println(&quot;Title: &quot; + driver.getTitle());
        driver.quit();
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Run Tests Using Maven&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Run all tests:&lt;/div&gt;&lt;div&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;mvn test&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;General Tips From Experts for Answering Interview Questions&lt;/h2&gt;&lt;div&gt;Here are some expert tips from &lt;a href=&quot;https://www.themuse.com/advice/interview-questions-and-answers&quot; target=&quot;_blank&quot;&gt;The Muse&lt;/a&gt;,&amp;nbsp;&lt;a href=&quot;https://www.indeed.com/career-advice/interviewing/top-interview-questions-and-answers&quot; target=&quot;_blank&quot;&gt;indeed&lt;/a&gt;,&amp;nbsp;&lt;a href=&quot;https://www.careers.govt.nz/job-hunting/interviews/tips-for-answering-interview-questions/&quot;&gt;careers.govt.nz&lt;/a&gt;, and &lt;a href=&quot;https://www.theguardian.com/lifeandstyle/2025/jan/20/perfect-cv-acing-interview-experts-23-ways-job-of-your-dreams&quot; target=&quot;_blank&quot;&gt;The Guardian&lt;/a&gt; articles on how to answer interview questions more&amp;nbsp;precisely to get success.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Understand the Question&lt;/b&gt; – Ensure that you take a moment before answering the question and ask for clarification if needed.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Match Answers to the Company’s Needs&lt;/b&gt;:&amp;nbsp;Research about the company and personalize your responses accordingly.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Stay Positive &amp;amp; Professional&lt;/b&gt;:&amp;nbsp;Avoid insulting past employers and use challenges as a learning experience.&lt;/li&gt;&lt;li&gt;Here are a few expert tips from the Muse article&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;b&gt;Use the STAR Method&lt;/b&gt; – For more clarity, organize your responses using Situation, Task, Action, and Result.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Be Concise and Relevant&lt;/b&gt; – Try to keep your answers under 2 minutes and avoid going into unnecessary detail.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Highlight Results &amp;amp; Impact&lt;/b&gt;: You can showcase your impacts using numbers and&amp;nbsp;metrics, which&amp;nbsp;makes your achievements clear, memorable, and results-driven.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Practice, But Don’t Memorize&lt;/b&gt;:&amp;nbsp;Practice answering common questions while keeping the responses natural.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2025/03/selenium-interview-questions-and-answers.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-6507102475593820205</guid><pubDate>Sat, 01 Mar 2025 11:12:00 +0000</pubDate><atom:updated>2025-03-07T19:14:32.803-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">selenium webdriver</category><title>How to Download EdgeDriver for Selenium (Step-by-Step Guide)</title><description>&lt;p&gt;You need&amp;nbsp;EdgeDriver to run Selenium tests in Microsoft Edge browser. It lets&amp;nbsp;Selenium WebDriver interact with MS Edge browser just like a real user.&lt;/p&gt;&lt;p&gt;Here is a step-by-step guide to&amp;nbsp;download, install, and set up the right version of EdgeDriver.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Step 1: Check Your Microsoft Edge Version&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;div&gt;Before downloading EdgeDriver, you must check your Edge browser version.&lt;/div&gt;&lt;p&gt;Here’s how to check:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Open &lt;b&gt;Microsoft Edge&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Click the &lt;b&gt;three dots (⋮)&lt;/b&gt; at the top right corner - Select &lt;b&gt;Help and Feedback&lt;/b&gt; - Select &lt;b&gt;About Microsoft Edge&lt;/b&gt;. My version is&amp;nbsp;Version 133.0.3065.92.&lt;/li&gt;&lt;li&gt;Update if you are using an older version. Note the version number (e.g., 133.x.x.x).&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6crlCWBdAwbYkmb350i7hPVjE7y30C8h45usO1jwYoiSZiFwEiY8Qs1lw3OVl3g5QI4UJA2dbAMbSofQ4U4_4rw7nOn_M1ayjFv0G0y3D55V7f9fsWZQYkrh79kWnstxiCAeu4upw3fGvtvuNK8t5nIIUpItuI-F4PtMUpsnimZZGKrKPtrGTaswZxojU/s867/check%20microsoft%20edge%20browser%20version.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Check microsoft edge browser version&quot; border=&quot;0&quot; data-original-height=&quot;255&quot; data-original-width=&quot;867&quot; height=&quot;188&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6crlCWBdAwbYkmb350i7hPVjE7y30C8h45usO1jwYoiSZiFwEiY8Qs1lw3OVl3g5QI4UJA2dbAMbSofQ4U4_4rw7nOn_M1ayjFv0G0y3D55V7f9fsWZQYkrh79kWnstxiCAeu4upw3fGvtvuNK8t5nIIUpItuI-F4PtMUpsnimZZGKrKPtrGTaswZxojU/w640-h188/check%20microsoft%20edge%20browser%20version.png&quot; title=&quot;Steps to check microsoft edge browser version.&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;b&gt;Why does this matter?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;Many people keep complaining that the edge driver is not working in Selenium. The reason is EdgeDriver version updates with a version of the Edge browser, and a mismatch in versions can generate errors when you run Selenium tests.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now let’s see how to download the correct &lt;b&gt;version of EdgeDriver&lt;/b&gt;.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Are you looking to run selenium tests in Firefox browser? Here is a step-by-step guide on &lt;b&gt;&lt;a href=&quot;http://software-testing-tutorials-automation.com/2025/02/how-to-download-geckodriver-for-firefox-in-selenium.html&quot; target=&quot;_blank&quot;&gt;how to download and set up&amp;nbsp;GeckoDriver for Selenium&lt;/a&gt;&lt;/b&gt;.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Step 2: Download EdgeDriver For Selenium WebDriver&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;div&gt;To download EdgeDriver, follow these simple steps:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Go to the &lt;b&gt;&lt;a href=&quot;https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads&quot; target=&quot;_blank&quot;&gt;official Microsoft Edge WebDriver page&lt;/a&gt;&lt;/b&gt;:&lt;/li&gt;&lt;li&gt;As per your Edge browser version and OS,&amp;nbsp;download the corresponding EdgeDriver from the stable channel.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju2ZKeDR0W9vMLkFpDtqQKWXPchpy8cFlBnivj3kbn3vxHRlLafWDwhXZ-V2a3OSqHeExnPJZ0zO6jHgz1n6kFSuEYHgiXb8ZKZ937ppDa-vqXC318lVi2UpKluQHFdYTSqa63Qh4r8r7rYgQEicA-w1znkss8zk7LxXlfHDPy18AND84pxNdqE8d-bd5p/s1295/download%20edge%20driver%20as%20per%20your%20browser%20version%20and%20operating%20system.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Download Edge Driver&quot; border=&quot;0&quot; data-original-height=&quot;455&quot; data-original-width=&quot;1295&quot; height=&quot;224&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju2ZKeDR0W9vMLkFpDtqQKWXPchpy8cFlBnivj3kbn3vxHRlLafWDwhXZ-V2a3OSqHeExnPJZ0zO6jHgz1n6kFSuEYHgiXb8ZKZ937ppDa-vqXC318lVi2UpKluQHFdYTSqa63Qh4r8r7rYgQEicA-w1znkss8zk7LxXlfHDPy18AND84pxNdqE8d-bd5p/w640-h224/download%20edge%20driver%20as%20per%20your%20browser%20version%20and%20operating%20system.png&quot; title=&quot;edge driver download for selenium as per your edge version and operating system&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;Now let&#39;s see how to set up the edge driver.&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Step 3: Extract and Set Up EdgeDriver&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;Once downloaded, you need to &lt;b&gt;extract the ZIP file&lt;/b&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Extract the EdgeDriver ZIP file to a location like D:\WebDriver\&lt;/li&gt;&lt;li&gt;Inside the folder, you’ll find msedgedriver.exe.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;But to run EdgeDriver in your selenium tests, you need to add it to the system PATH.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here’s how:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Search for Environment Variables in Windows.&lt;/li&gt;&lt;li&gt;Under System Variables, find Path and click Edit.&lt;/li&gt;&lt;li&gt;Click New, then paste your folder path (e.g., D:\WebDriver\).&lt;/li&gt;&lt;li&gt;Click OK and restart your computer.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;Now, EdgeDriver is ready to run.&lt;/div&gt;&lt;h2&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Step 4: Run EdgeDriver with Selenium&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;div&gt;To make sure EdgeDriver is working, let’s write a quick Selenium test script. Use the given edge driver set up code in your selenium test and run it.&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;b&gt;Example of Microsoft Edge Driver in Selenium&lt;/b&gt;&lt;br /&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;// Set the path to EdgeDriver (only needed if it&#39;s not in system PATH)
        System.setProperty(&quot;webdriver.edge.driver&quot;, &quot;D:\\WebDriver\\msedgedriver.exe&quot;);

        // Initialize EdgeDriver
        WebDriver driver = new EdgeDriver();&lt;/span&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div&gt;This example script will help you run the Selenium test on Microsoft Edge browser. Now, you can:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Open Edge automatically when running the Selenium test.&lt;/li&gt;&lt;li&gt;Navigate to websites.&lt;/li&gt;&lt;li&gt;Extract page titles &amp;amp; interact with web elements.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Tip&lt;/b&gt;: Always use the latest Selenium version and update EdgeDriver whenever Edge browser&#39;s version updates.&lt;/div&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2025/03/edge-driver-download-for-selenium.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6crlCWBdAwbYkmb350i7hPVjE7y30C8h45usO1jwYoiSZiFwEiY8Qs1lw3OVl3g5QI4UJA2dbAMbSofQ4U4_4rw7nOn_M1ayjFv0G0y3D55V7f9fsWZQYkrh79kWnstxiCAeu4upw3fGvtvuNK8t5nIIUpItuI-F4PtMUpsnimZZGKrKPtrGTaswZxojU/s72-w640-h188-c/check%20microsoft%20edge%20browser%20version.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-2866757406205010170</guid><pubDate>Sat, 01 Mar 2025 06:38:00 +0000</pubDate><atom:updated>2025-03-04T18:58:24.889-08:00</atom:updated><title>How to Download and Set Up GeckoDriver In Selenium (Step-by-Step Guide)</title><description>&lt;p&gt;Are you looking to automate &lt;b&gt;Firefox with Selenium WebDriver&lt;/b&gt;? You need GeckoDriver.&lt;/p&gt;&lt;p&gt;But many beginners struggle with setting it up correctly.&lt;/p&gt;&lt;p&gt;If that’s you, don’t worry.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Let&#39;s see how to download and use geckodriver in selenium test step by step.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;What is GeckoDriver? (And Why Do You Need It?)&lt;/h2&gt;&lt;div&gt;&lt;div&gt;Simply put, &lt;b&gt;GeckoDriver acts as a bridge&lt;/b&gt; between Selenium and Firefox. Without it, your automation test scripts will not work in the Firefox browser.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;That is the reason you need to install it before running Selenium WebDriver with Java.&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Now, let’s get started.&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Step 1: Download GeckoDriver&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;This is the easy part.&lt;/p&gt;&lt;p&gt;Just follow these steps:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Make sure You have the latest version of the Firefox browser. My version is&amp;nbsp;135.0.1.&lt;/li&gt;&lt;li&gt;Go to the official &lt;b&gt;&lt;a href=&quot;https://github.com/mozilla/geckodriver/releases&quot; target=&quot;_blank&quot;&gt;GeckoDriver download page&lt;/a&gt;&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Download the latest version based on your operating system:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Windows&lt;/b&gt;: geckodriver-vx.x.x-win-aarch64.zip&lt;/li&gt;&lt;li&gt;&lt;b&gt;Mac&lt;/b&gt;:&amp;nbsp;geckodriver-vX.X.X-macos.tar.gz&lt;/li&gt;&lt;li&gt;&lt;b&gt;Linux&lt;/b&gt;: geckodriver-vx.x.x-linux64.tar.gz&lt;/li&gt;&lt;li&gt;Extract the file to a known location on your system.&lt;/li&gt;&lt;li&gt;You will get&amp;nbsp;geckodriver.exe file in the extracted folder.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlR0AxEeS9BFu1JVMFEiYA_tRAsuzUI6L-5bcf0RnIN9pKSW17kdf8SGsV5ZwApPGRplyHzz8uD7Y8dzptfXNYQhS46KVlShv5RX8lMFoI8UGF56a10ccK9VD8MqMZIBYW8BcJhA26LCFZPcKghsadDI1T1WqA-LALgVHQMLZjKMbxTPxkMmgs3-hbF1VB/s923/download%20GeckoDriver%20for%20windows,%20mac%20and%20linux%20operating%20systems.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Download gecko driver&quot; border=&quot;0&quot; data-original-height=&quot;511&quot; data-original-width=&quot;923&quot; height=&quot;354&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlR0AxEeS9BFu1JVMFEiYA_tRAsuzUI6L-5bcf0RnIN9pKSW17kdf8SGsV5ZwApPGRplyHzz8uD7Y8dzptfXNYQhS46KVlShv5RX8lMFoI8UGF56a10ccK9VD8MqMZIBYW8BcJhA26LCFZPcKghsadDI1T1WqA-LALgVHQMLZjKMbxTPxkMmgs3-hbF1VB/w640-h354/download%20GeckoDriver%20for%20windows,%20mac%20and%20linux%20operating%20systems.png&quot; title=&quot;download gecko driver for windows, mac and linux operating systems.&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Are you looking to run Selenium tests in Chrome browser? You can find a guide on &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/02/chrome-driver-download-for-selenium.html&quot; target=&quot;_blank&quot;&gt;&lt;b&gt;how to download ChromeDriver for Selenium&lt;/b&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Done? Great! Now, let’s move on.&lt;/p&gt;&lt;div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Step 2: Add GeckoDriver to System Path (Optional, But Recommended)&lt;/span&gt;&lt;/h2&gt;&lt;/div&gt;&lt;p&gt;This step is optional, but it will help you avoid a lot of headaches later.&lt;/p&gt;&lt;p&gt;Why?&lt;/p&gt;&lt;p&gt;Because adding GeckoDriver to your system path means you won’t have to specify its location in every script.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Move geckodriver.exe to D:\geckodriver\ folder.&lt;/li&gt;&lt;li&gt;Add D:\geckodriver\&amp;nbsp;to System Environment Variables:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Search for &quot;&lt;b&gt;Environment Variables&lt;/b&gt;&quot; in the Start menu.&lt;/li&gt;&lt;li&gt;Click &lt;b&gt;Edit the system environment variables&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Under System Variables, find &lt;b&gt;Path &lt;/b&gt;and click Edit.&lt;/li&gt;&lt;li&gt;Click New and add D:\geckodriver\&lt;/li&gt;&lt;li&gt;Click OK to save.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div&gt;Do you know which other browsers and languages are supported by Selenium? Here is a&amp;nbsp;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/02/what-is-webdriver-in-selenium.html&quot; target=&quot;_blank&quot;&gt;&lt;b&gt;list of browsers and programming languages supported by Selenium WebDriver&lt;/b&gt;&lt;/a&gt;.&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Step 3: Write Java Code to Launch Firefox&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;Let’s put GeckoDriver to the test.&lt;/p&gt;&lt;p&gt;Here’s a simple Java program to launch &lt;b&gt;Firefox with Selenium&lt;/b&gt;:&lt;/p&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;font-family: arial; font-size: 12px; overflow-wrap: normal; word-wrap: normal;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;WebDriver driver = new FirefoxDriver();
        driver.get(&quot;https://only-testing-blog.blogspot.com/&quot;);&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;
&lt;/code&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;driver.close();&lt;/span&gt;&lt;/pre&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;Troubleshooting: Fixing Common Errors&lt;/h2&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Still running into issues? Let’s fix them.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Error&lt;/b&gt;: ‘geckodriver’ is not recognized as an internal or external command.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Fix&lt;/b&gt;:&amp;nbsp;Make sure GeckoDriver is added to your system’s PATH.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Error&lt;/b&gt;: WebDriverException: Message: geckodriver executable needs to be in PATH&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Fix&lt;/b&gt;:&amp;nbsp;Double-check that GeckoDriver is accessible from your terminal.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Error&lt;/b&gt;: SessionNotCreatedException: This version of Firefox is not supported&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Fix&lt;/b&gt;:&amp;nbsp;Update both GeckoDriver and Firefox to the latest versions.&lt;/div&gt;&lt;/div&gt;&lt;p&gt;You did it!&lt;/p&gt;&lt;p&gt;By following this guide, you’ve successfully:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Downloaded GeckoDriver&lt;/li&gt;&lt;li&gt;Configured it for Java and Selenium.&lt;/li&gt;&lt;li&gt;Written and executed a Selenium script for Firefox.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, you’re all set to automate selenium tests in Firefox browser.&lt;/p&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2025/02/how-to-download-geckodriver-for-firefox-in-selenium.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlR0AxEeS9BFu1JVMFEiYA_tRAsuzUI6L-5bcf0RnIN9pKSW17kdf8SGsV5ZwApPGRplyHzz8uD7Y8dzptfXNYQhS46KVlShv5RX8lMFoI8UGF56a10ccK9VD8MqMZIBYW8BcJhA26LCFZPcKghsadDI1T1WqA-LALgVHQMLZjKMbxTPxkMmgs3-hbF1VB/s72-w640-h354-c/download%20GeckoDriver%20for%20windows,%20mac%20and%20linux%20operating%20systems.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-525436790572335011</guid><pubDate>Thu, 27 Feb 2025 11:47:00 +0000</pubDate><atom:updated>2025-03-12T23:00:22.334-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">selenium webdriver</category><title>Selenium WebDriver: Compact &amp; Concise Web Browser Automation API</title><description>&lt;p&gt;Selenium WebDriver is a popular &amp;amp; widely used web browser automation tool that automates web application testing in all major browsers and operating systems. This remote-control open-source API allows you to create and execute automation tests natively in browsers using multiple supported programming languages.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;History of Selenium WebDriver&lt;/h2&gt;&lt;div&gt;Selenium and WebDriver were created by distinct individuals, but in the end, they became one powerful automation tool.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Before moving ahead,&amp;nbsp;we should quickly examine the history of Selenium and WebDriver&#39;s development.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Selenium&lt;/b&gt;:&lt;/h3&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Development:&lt;/b&gt;&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Initially, Selenium was designed and developed by Jason Huggins in 2004 when he was working at ThoughtWorks in Chicago.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Primarily, he developed it to automate web application testing.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Later on, Paul Hammant, Aslak Hellesoy, Mike Melia, Aslak, and Obie Fernandez joined him.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;They worked collectively to develop and improve different components of Selenium, like the server and client driver, and make it an open source framework.&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Problem&lt;/b&gt;:&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;The initial version of Selenium (RC) was heavy due to its reliance on the proxy server and JavaScript injection to automate tests for web browsers.&lt;/p&gt;&lt;div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;WebDriver&lt;/b&gt;&lt;/h4&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Development:&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Around 2007, Simon Stewart came up with the WebDriver API, which uses separate clients for each browser.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Compared to Selenium RC, it was lighter and easier to use.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;In 2008, they made the decision to combine both projects.&amp;nbsp;This merger brought the best of both worlds: Selenium’s flexibility and WebDriver’s native browser control.&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;(&lt;a href=&quot;https://www.selenium.dev/history/&quot; target=&quot;_blank&quot;&gt;Source&lt;/a&gt;)&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;From&amp;nbsp;05 June 2018, it is a &lt;a href=&quot;https://www.w3.org/TR/webdriver1/&quot; target=&quot;_blank&quot;&gt;W3C-recommended&lt;/a&gt; browser automation testing tool.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;How Does WebDriver Work?&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;At its core, Selenium WebDriver is like a &lt;b&gt;remote control for your web browser&lt;/b&gt;. It &lt;b&gt;directly communicates&lt;/b&gt; with the browser and executes actions. Let&#39;s see how WebDriver works step by step.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDHbYpez5_ij9fmbZtWwThvtohQuYdL3kYI2mJVI3uZFZ4_q-YhOa_gZXE6N7nAEAEx3aa3TcKHNJXj9fRhxhXboQj74OH93nHD_A3347iWZB9gUtRBjn4rOBrivzxmEp5mwomGeZl7VLz76VkDWBkxYadTuJSUd8WSJgMq08T2KfJrjjvP-sNfORyXdpa/s731/How%20Does%20WebDriver%20Work.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;How Does WebDriver Work&quot; border=&quot;0&quot; data-original-height=&quot;82&quot; data-original-width=&quot;731&quot; height=&quot;72&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDHbYpez5_ij9fmbZtWwThvtohQuYdL3kYI2mJVI3uZFZ4_q-YhOa_gZXE6N7nAEAEx3aa3TcKHNJXj9fRhxhXboQj74OH93nHD_A3347iWZB9gUtRBjn4rOBrivzxmEp5mwomGeZl7VLz76VkDWBkxYadTuJSUd8WSJgMq08T2KfJrjjvP-sNfORyXdpa/w640-h72/How%20Does%20WebDriver%20Work.png&quot; title=&quot;Work flow of selenium WebDriver&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;1. Test Script (Your Code)&lt;/h3&gt;&lt;div&gt;You can write a WebDriver automation test script in your preferred language like&amp;nbsp;Java, Python, C#, JavaScript, etc. You will learn all supported languages by WebDriver in the upcoming section of this article.&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;These scripts contain:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Command to open a browser.&lt;/li&gt;&lt;li&gt;Instructions to click buttons, fill out forms, or extract text.&lt;/li&gt;&lt;li&gt;Assertions to verify expected results.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;2. WebDriver API (Middleman)&lt;/h3&gt;&lt;div&gt;&lt;div&gt;Selenium WebDriver serves as a bridge between your code and the browser when your test script communicates with it.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;3. Browser Driver (Translator)&lt;/h3&gt;&lt;div&gt;Each browser has a dedicated WebDriver (ChromeDriver, GeckoDriver, etc.).&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;WebDriver sends your test commands to the browser driver.&lt;/li&gt;&lt;li&gt;The browser driver translates them into native browser actions.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;In the upcoming section, You will learn about WebDriver-supported drivers.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;4. Browser Execution&lt;/h3&gt;&lt;div&gt;&lt;div&gt;The browser driver controls the browser directly and performs actions like:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Clicking buttons&lt;/li&gt;&lt;li&gt;Typing in fields&lt;/li&gt;&lt;li&gt;Navigating between pages&lt;/li&gt;&lt;li&gt;Taking screenshots&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;5. Response Back to the Test Script&lt;/h3&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;After executing commands, the browser sends a response back to WebDriver.&lt;/li&gt;&lt;li&gt;WebDriver then sends results to your test script (pass/fail, error messages, etc.).&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;And that’s how Selenium WebDriver automates your browser like a pro!&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;WebDriver-Supported Browsers, Languages&lt;/h2&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBJq4Yql7CzEtTtDAoNiIZuUWN_1AjAzn2BCsc3Z0m_OfqgHvoWJKkVGv5MUMUGqJIcBCGjc1K_C2vDRIAvV5ewX9UuSTkdqW8QU0lBGT255gGn6LFfoimedmtFRHL0ESSV08D5HLPlspPuYkGTW5EN9wM8wi5wzUfwLHcKkYDWJ3nnw5LKdijbPmH5zGf/s800/WebDriver%20Supported%20browsers.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Multiple browsers supported by selenium WebDriver&quot; border=&quot;0&quot; data-original-height=&quot;400&quot; data-original-width=&quot;800&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBJq4Yql7CzEtTtDAoNiIZuUWN_1AjAzn2BCsc3Z0m_OfqgHvoWJKkVGv5MUMUGqJIcBCGjc1K_C2vDRIAvV5ewX9UuSTkdqW8QU0lBGT255gGn6LFfoimedmtFRHL0ESSV08D5HLPlspPuYkGTW5EN9wM8wi5wzUfwLHcKkYDWJ3nnw5LKdijbPmH5zGf/w640-h320/WebDriver%20Supported%20browsers.png&quot; title=&quot;Selenium WebDriver supports Google chrome, Mozilla Firefox, Microsoft Edge, Apple Safari, and Internet Explorer browsers&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Browsers&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;WebDriver can directly talk to the browser through automation drivers. Selenium WebDriver-supported browser drivers are:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;ChromeDriver &lt;/b&gt;for Google Chrome (OS Support: Windows/Linux/macOS)&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Steps to&amp;nbsp;&lt;b&gt;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/02/chrome-driver-download-for-selenium.html&quot; target=&quot;_blank&quot;&gt;download and set up chromedriver for Selenium&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;GeckoDriver &lt;/b&gt;for Mozilla Firefox (OS Support: Windows/Linux/macOS)&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Steps to &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/02/how-to-download-geckodriver-for-firefox-in-selenium.html&quot; target=&quot;_blank&quot;&gt;&lt;b&gt;download&amp;nbsp;and set up GeckoDriver for Selenium&lt;/b&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;EdgeDriver &lt;/b&gt;for Microsoft Edge&amp;nbsp;(OS Support: Windows/Linux/macOS)&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Steps to &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/edge-driver-download-for-selenium.html&quot; target=&quot;_blank&quot;&gt;&lt;b&gt;download and install&amp;nbsp;EdgeDriver for Selenium&lt;/b&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;SafariDriver &lt;/b&gt;for Apple Safari browser&amp;nbsp;(OS Support:&amp;nbsp;Mac-only)&lt;/li&gt;&lt;li&gt;&lt;b&gt;InternetExplorerDriver &lt;/b&gt;for&amp;nbsp;Internet Explorer (OS Support:&amp;nbsp;Windows. Legacy support)&lt;/li&gt;&lt;li&gt;&lt;b&gt;OperaDriver &lt;/b&gt;For Opera (&lt;a href=&quot;https://github.com/bonigarcia/webdrivermanager/issues/808&quot; target=&quot;_blank&quot;&gt;Discontinued,&amp;nbsp;&lt;/a&gt;but still you can use WebDriverManager)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;strong data-end=&quot;1547&quot; data-start=&quot;1522&quot;&gt;Why does this matter?&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Cross-Browser Testing:&lt;/b&gt;&amp;nbsp;You can make sure that your website works smoothly in different browsers.&lt;/li&gt;&lt;li&gt;&lt;b&gt;User Experience:&lt;/b&gt; Pages are rendered differently by different browsers.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Market Coverage:&lt;/b&gt; Accessibility can be ensured by testing on multiple browsers due to user preferences.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Bug Detection:&lt;/b&gt; Some issues only appear in specific browsers. You can find those hidden bugs early!&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Languages&lt;/h3&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2Yg-epQxI4lhBV9Yl-gWJv2FoTt7v1KS2uV0PVJ8u9c8rPz7Re3CptA3IHsiYbtbSkfwV3tYNq287GsnI0bT4-ehWElBx0mU7v4FgBXZWvJIqO3pw-NOXulAwQceKRG81ta6vDFeYxeYlqC3p4p3RbIqvCqKzeuTv2bzth4dw2WCMXX3PNqz8fUX-82hI/s800/WebDriver%20Supported%20languages.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;WebDriver Support multiple languages&quot; border=&quot;0&quot; data-original-height=&quot;400&quot; data-original-width=&quot;800&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2Yg-epQxI4lhBV9Yl-gWJv2FoTt7v1KS2uV0PVJ8u9c8rPz7Re3CptA3IHsiYbtbSkfwV3tYNq287GsnI0bT4-ehWElBx0mU7v4FgBXZWvJIqO3pw-NOXulAwQceKRG81ta6vDFeYxeYlqC3p4p3RbIqvCqKzeuTv2bzth4dw2WCMXX3PNqz8fUX-82hI/w640-h320/WebDriver%20Supported%20languages.png&quot; title=&quot;Selenium WebDriver supports multiple programming languages like Java, Python, C#, JavaScript, Ruby, PHP, and Perl&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;Selenium WebDriver supports multiple programming languages, including:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Java&lt;/b&gt;: Most widely used, strong community support.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Python&lt;/b&gt;: Easy syntax, great for beginners &amp;amp; automation scripts.&lt;/li&gt;&lt;li&gt;&lt;b&gt;C#&lt;/b&gt;: Popular for .NET developers &amp;amp; enterprise applications.&lt;/li&gt;&lt;li&gt;&lt;b&gt;JavaScript&lt;/b&gt;: Ideal for web apps, works well with Node.js.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Ruby&lt;/b&gt;: Simple syntax, great for quick scripting.&lt;/li&gt;&lt;li&gt;&lt;b&gt;PHP&lt;/b&gt;: Preferred for PHP developers to perform&amp;nbsp;server-side web automation.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Perl&lt;/b&gt;:&amp;nbsp;Older but still useful for legacy automation.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;Are you confused which language to use? Here is a detailed guide on &lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/selenium-supported-languages.html&quot; target=&quot;_blank&quot;&gt;Selenium supported languages&lt;/a&gt; and which best suits you.&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Why Does This Matter?&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Flexibility:&lt;/b&gt;&amp;nbsp;You can write tests in the language your team already uses.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Integration:&lt;/b&gt;&amp;nbsp;Works seamlessly with different tech platforms and frameworks like JUnit, TestNG, PyTest, NUnit, Mocha, etc.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Wider Adoption:&lt;/b&gt;&amp;nbsp;More developers can contribute without learning a new language.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Scalability:&lt;/b&gt;&amp;nbsp;Supports various development environments (backend, frontend, mobile, etc.).&lt;/li&gt;&lt;/ul&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Locators&lt;/h3&gt;&lt;div&gt;Selenium WebDriver supports multiple locators as below.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/find-element-by-id-in-selenium.html&quot; target=&quot;_blank&quot;&gt;Find Element by ID&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/name-locator-in-selenium.html&quot; target=&quot;_blank&quot;&gt;Name Locator In Selenium&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/selenium-find-element-by-class.html&quot; target=&quot;_blank&quot;&gt;Find element by Class Name&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://software-testing-tutorials-automation.com/2025/03/tagname-locator-in-selenium.html&quot; target=&quot;_blank&quot;&gt;TagName Locator in Selenium&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/linktext-selenium.html&quot; target=&quot;_blank&quot;&gt;Element Locator Linktext in Selenium&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://software-testing-tutorials-automation.com/2025/03/partial-link-text-in-selenium.html&quot; target=&quot;_blank&quot;&gt;Partial Link Text in Selenium&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Find Element by&amp;nbsp;CSS Selector&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2025/03/xpath-in-selenium.html&quot; target=&quot;_blank&quot;&gt;Write XPath in Selenium&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Pros and Cons of Selenium WebDriver&lt;/h2&gt;&lt;div&gt;First of all, let&#39;s look at the advantages/benefits of Selenium WebDriver.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Pros:&lt;/h3&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Supports Multiple Programming Languages&lt;/b&gt;: You can work with your preferred language like&amp;nbsp;Java, Python, C#, JavaScript, Ruby, PHP, and Perl.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Supports Cross-Browser Testing&lt;/b&gt;: You can run your test scripts in&amp;nbsp;&lt;span data-end=&quot;457&quot; data-start=&quot;413&quot;&gt;Chrome, Firefox, Edge, Safari, Opera, and IE browsers.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span data-end=&quot;457&quot; data-start=&quot;413&quot;&gt;&lt;b&gt;Supports Cross-Platform Testing&lt;/b&gt;: You can run WebDriver tests across multiple operating systems like&amp;nbsp;Windows, Mac, and Linux.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;Open-Source &amp;amp; Free:&lt;/b&gt;&amp;nbsp;No licensing costs.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Works with Real Browsers&lt;/b&gt;: You can perform accurate testing with a real browser as it interacts directly with it.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Integrates with Popular Testing Frameworks&lt;/b&gt;:&amp;nbsp;Works seamlessly with JUnit, TestNG, PyTest, NUnit, etc. for structured test execution.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Supports Parallel &amp;amp; Remote Testing&lt;/b&gt;:&amp;nbsp;With Selenium Grid, you can run tests on multiple machines &amp;amp; browsers at once.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Extensive Community &amp;amp; Resources&lt;/b&gt;: It is being used by a significant amount of developers and testers. You can quickly find solutions on online forums and Selenium community websites.&lt;/li&gt;&lt;/ul&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Cons:&lt;/b&gt;&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;Here are the disadvantages/limitations of Selenium WebDriver&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;No Built-in Reporting:&lt;/b&gt; You need third-party tools like&amp;nbsp;ExtentReports, Allure, and TestNG to generate test reports.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Steep Learning Curve for Beginners:&amp;nbsp;&lt;/b&gt;Requires coding knowledge; not as beginner-friendly as codeless testing tools like TestProject or Katalon.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Limited Support for Desktop &amp;amp; Mobile Apps: &lt;/b&gt;Primarily, it is developed for web application testing only. You can use&amp;nbsp;Appium for&amp;nbsp;mobile testing and&amp;nbsp;WinAppDriver to test&amp;nbsp;desktop apps.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Handling Dynamic Elements Can Be Tricky&lt;/b&gt;: Websites using AJAX, dynamic DOM changes, or animations might require explicit waits and extra handling.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Can Be Slow Compared to Headless Testing Tools&lt;/b&gt;: Since it interacts directly with actual browsers, tests might run slower compared to tools like Cypress (which runs in a JavaScript engine).&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;In Summary, It is best for web automation, cross-browser testing, and open-source flexibility. However, it is not ideal for beginners, desktop apps, or advanced reporting without extra tools.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Despite challenges, Selenium WebDriver remains one of the most effective automation tools available today!&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Alternatives of Selenium WebDriver&lt;/b&gt;&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Despite technological advancements, Selenium WebDriver remains one of the best web application automation testing tools by 2025. However, other options may be more advantageous depending on your requirements. Here are some alternatives to consider:&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;1. Cypress (Best for JavaScript &amp;amp; Frontend Testing)&lt;/h3&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Why Use It?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Faster execution (runs inside the browser, unlike Selenium).&lt;/li&gt;&lt;li&gt;Easy setup with Node.js.&lt;/li&gt;&lt;li&gt;Better debugging with real-time reloading.&lt;/li&gt;&lt;li&gt;Built-in screenshot &amp;amp; video recording.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Limitations&lt;/b&gt;:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Only supports JavaScript.&lt;/li&gt;&lt;li&gt;Works mainly for front-end testing (not for cross-browser automation).&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;2. Playwright (Best for Modern Browser Automation)&lt;/h3&gt;&lt;div&gt;&lt;b&gt;Why Use It?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Supports multiple languages (JavaScript, Python, C#, Java, TypeScript).&lt;/li&gt;&lt;li&gt;Works with multiple browsers (Chromium, Firefox, WebKit).&lt;/li&gt;&lt;li&gt;Handles auto-waiting &amp;amp; retries (better for dynamic pages).&lt;/li&gt;&lt;li&gt;Headless mode for faster execution.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Limitations&lt;/b&gt;:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Newer tool. less community support compared to Selenium.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Why Use It?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Built for Google Chrome &amp;amp; Chromium automation.&lt;/li&gt;&lt;li&gt;Great for web scraping &amp;amp; PDF generation.&lt;/li&gt;&lt;li&gt;Fast execution with headless mode.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Limitations&lt;/b&gt;:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Works only&amp;nbsp;with Chrome browser (not a true cross-browser tool).&lt;/li&gt;&lt;li&gt;Requires Node.js &amp;amp; JavaScript knowledge so not beginner friendly.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;Selenium WebDriver remains one of the best tools for cross-browser automation, web testing, and scalability. While it has some limitations, its flexibility, large community, and open-source nature make it a top choice for automation testers in 2025!&lt;/div&gt;&lt;/div&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2025/02/what-is-webdriver-in-selenium.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDHbYpez5_ij9fmbZtWwThvtohQuYdL3kYI2mJVI3uZFZ4_q-YhOa_gZXE6N7nAEAEx3aa3TcKHNJXj9fRhxhXboQj74OH93nHD_A3347iWZB9gUtRBjn4rOBrivzxmEp5mwomGeZl7VLz76VkDWBkxYadTuJSUd8WSJgMq08T2KfJrjjvP-sNfORyXdpa/s72-w640-h72-c/How%20Does%20WebDriver%20Work.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-7650559478988130316</guid><pubDate>Thu, 09 Jan 2025 17:00:00 +0000</pubDate><atom:updated>2025-01-29T21:44:56.295-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Apache Jmeter</category><category domain="http://www.blogger.com/atom/ns#">jmeter testing</category><title>Apache JMeter: Load and Performance Testing Made Simple</title><description>&lt;h2 style=&quot;text-align: left;&quot;&gt;Introduction:&amp;nbsp;Load and Performance Testing Using Apache JMeter&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;The performance, reliability, and usability of your software application are crucial factors in today&#39;s fast-paced, competitive digital world. It is crucial to check how your application performs during both regular and peak usage since users expect a smooth and reliable experience when visiting and navigating your website. This is where load and performance testing using Apache JMeter comes into play.&amp;nbsp;&lt;/p&gt;&lt;span&gt;&lt;/span&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Using JMeter for testing, testers, and developers can identify performance-related potential bottlenecks that cause the issue. Whether you’re conducting Apache JMeter load testing to evaluate server stability or JMeter performance testing to measure response times, JMeter software provides a complete understanding of your application’s behavior under different conditions, as it can simulate real-world traffic, making it an invaluable tool for developers and testers.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUIG4j7iWHgasJ4f3ABWiacw-8FroO6P_5SV9nuYjhA6eKLjJTpt-cmcnvY4rT0lOiViHLZKQ1F6qHcFxCUbfpOwnb_qctOAlnWaJdLTFqHfccS5hjz96o71fN9oYTOpYJoQNOItZVYTONCXsoFBngS6AdzGPfaMe4XVzVWHlwP9a_xBLWde1DZh8QGUCA/s1024/Apache%20JMeter%20for%20load%20and%20performance%20testing.webp&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Apache JMeter for load and performance testing&quot; border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1024&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUIG4j7iWHgasJ4f3ABWiacw-8FroO6P_5SV9nuYjhA6eKLjJTpt-cmcnvY4rT0lOiViHLZKQ1F6qHcFxCUbfpOwnb_qctOAlnWaJdLTFqHfccS5hjz96o71fN9oYTOpYJoQNOItZVYTONCXsoFBngS6AdzGPfaMe4XVzVWHlwP9a_xBLWde1DZh8QGUCA/w320-h320/Apache%20JMeter%20for%20load%20and%20performance%20testing.webp&quot; title=&quot;Apache JMeter for load and performance testing&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;What is Apache JMeter software?&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Apache JMeter is a powerful and widely used open-source tool that is designed by the&amp;nbsp;&lt;b&gt;&lt;a href=&quot;https://www.apache.org/&quot; target=&quot;_blank&quot;&gt;Apache Software Foundation&lt;/a&gt;&lt;/b&gt; to perform load and performance testing of software applications. It has a wide variety of robust features and a user-friendly interface that helps developers analyze the performance and scalability of web applications, APIs (application programming interfaces), databases, and many more.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;JMeter for testing allows you to simulate heavy loads on a server, group of servers, or network to assess the performance of an application under different traffic conditions. You can analyze server behavior and performance under different states of load conditions.&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Key Features and Benefits of Apache JMeter in Software Testing&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Here is the list of key features of Apache JMeter software:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Protocol Support&lt;/b&gt;: Apache JMeter supports a variety of protocols for testing as below.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Web: Protocols to test HTTP and HTTPS requests.&lt;/li&gt;&lt;li&gt;SOAP/REST: Protocol to test web services.&lt;/li&gt;&lt;li&gt;FTP: Network protocol&lt;/li&gt;&lt;li&gt;JDBC: Java API to connect and execute queries in a database.&lt;/li&gt;&lt;li&gt;LDAP: Lightweight Directory Access Protocol.&lt;/li&gt;&lt;li&gt;Message-oriented middleware (MOM) via JMS API.&lt;/li&gt;&lt;li&gt;Mail: SMTP, POP3, and IMAP protocols.&lt;/li&gt;&lt;li&gt;TCP: Transmission Control Protocol&lt;/li&gt;&lt;li&gt;Java Objects&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Scalability&lt;/b&gt;: You can perform stress testing using It by simulating thousands of users to measure the performance of the application and how it can handle growth.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Extensibility&lt;/b&gt;: It supports a wide variety of plugins, like custom thread groups, throughput shaping timers, PerfMon servers, performance monitoring, etc., to enhance the capability of JMeter software to meet specific testing needs.&lt;/li&gt;&lt;li&gt;&lt;b&gt;User-Friendly Interface&lt;/b&gt;: It provides a graphical user-friendly interface to perform load and performance testing.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Record &amp;amp; Playback&lt;/b&gt;: You can record your browser activities in it. Also, you can play back those navigations in your JMeter load testing plan.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Distributed testing&lt;/b&gt;: You can distribute a virtual user&#39;s load on different systems using the master-slave architecture that is provided by JMeter.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Reporting&lt;/b&gt;: You can generate different kinds of graphical reports in the form of graphs, charts, tables, and HTML in the JMeter performance testing tool to identify bottlenecks and optimize performance.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Assertions&lt;/b&gt;: You can compare and validate expected and actual responses of the server using assertions in JMeter. Response Assertion, Duration Assertion, BeanShell Assertion, and Size Assertion are a few examples of assertions in Apache JMeter.&lt;/li&gt;&lt;li&gt;&lt;b&gt;CI/CD Integration&lt;/b&gt;: It can be integrated with CI/CD tools like&amp;nbsp;&lt;b&gt;&lt;a href=&quot;http://jenkins.io/doc/book/using/using-jmeter-with-jenkins/&quot;&gt;Jenkins&lt;/a&gt;&lt;/b&gt;,&amp;nbsp;GitLab, and many more to streamline performance testing and ensure higher software quality.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Platform independent&lt;/b&gt;: It can run on different platforms and OS as it is a pure 100% Java-based application.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Community support&lt;/b&gt;: Apache JMeter has vast online community support to find any solution and support.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;All these are the key features of jmeter in software testing. These versatile and easy-to-use features of the Apache JMeter load testing tool make JMeter popular in the software testing industry.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Load And Performance Testing Using Apache JMeter&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Before learning about&amp;nbsp;Apache JMeter load testing and JMeter performance testing, You must know the difference between load and performance testing in software testing.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjVYuSpW6pb2f-6gclm1OKE_iDmSQiT4QCfMRPCbkCe20-0cN94KsfvdjCrxrNe3FEGkPbXtteN1joykfv-R0E2US15oIkG8DEIWMRMArEDVDQ0irmpKbZ0koPiRkPj8GBb64XbFtIsmaKpjtyVVBS2u02WQvv1CjM_4SNPSErIByhd7JldgKX2rHLgs9uE&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Key difference between load and performance testing&quot; data-original-height=&quot;298&quot; data-original-width=&quot;617&quot; height=&quot;310&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjVYuSpW6pb2f-6gclm1OKE_iDmSQiT4QCfMRPCbkCe20-0cN94KsfvdjCrxrNe3FEGkPbXtteN1joykfv-R0E2US15oIkG8DEIWMRMArEDVDQ0irmpKbZ0koPiRkPj8GBb64XbFtIsmaKpjtyVVBS2u02WQvv1CjM_4SNPSErIByhd7JldgKX2rHLgs9uE=w640-h310&quot; title=&quot;Key difference between load and performance testing&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Difference Between Load and Performance Testing&lt;/h3&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;What is Performance Testing?&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Performance testing is a practice that evaluates a system&#39;s responsiveness and stability under specific workload conditions. It evaluates the overall efficiency and responsiveness of a system under varying conditions.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;: Giving your car a complete checkup - checking everything from acceleration and handling to fuel efficiency.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;What is Apache JMeter Performance Testing?&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It&amp;nbsp;examines the system&#39;s speed, stability, and responsiveness under various conditions, including normal and stress scenarios, to ensure optimal performance.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;The Goal of JMeter Performance Testing&lt;/h4&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Measure response times and throughput for critical transactions.&lt;/li&gt;&lt;li&gt;Identify system stability under prolonged usage.&lt;/li&gt;&lt;li&gt;Detect performance issues like latency, memory leaks, or crashes.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;b&gt;Example of Performance Testing&lt;/b&gt;:&amp;nbsp;You have a JMeter performance test scenario for an e-commerce site to simulate users performing different actions like Registration, login, Navigating to the About us page, Adding product to basket and checkout, and contact us form submission. JMeter can be used to test how quickly a web page loads, how many transactions can be processed per second, and whether the application maintains its reliability over time.&lt;/div&gt;&lt;/div&gt;&lt;h4&gt;What is Load Testing?&lt;/h4&gt;&lt;p&gt;Load testing involves simulating multiple users accessing a software program simultaneously to evaluate its performance. Load testing focuses on assessing how an application performs under varying levels of user traffic and increasing loads.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Example&lt;/b&gt;: Test how your car handles behaves when it&#39;s fully loaded with passengers and cargo.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;What is Apache JMeter Load Testing?&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;It focuses on evaluating how a system behaves under concurrent expected or high user load to identify its capacity and scalability.&lt;/p&gt;&lt;h4&gt;The Goal of JMeter Load Testing&lt;/h4&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Identify the maximum number of users the system can handle without performance degradation.&lt;/li&gt;&lt;li&gt;Evaluate the application’s response time under normal and peak loads.&lt;/li&gt;&lt;li&gt;Detect bottlenecks that might arise due to high user activity.&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example of Load Testing&lt;/b&gt;: You have a JMeter load test scenario for an e-commerce site to simulate users performing different actions like registration, login, product addition to basket, and checkout.&amp;nbsp;JMeter can simulate users performing different actions and provides you a matrix to analyze application load capacity and based on that you can improve it.&lt;/p&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Different Types of Performance Testing in Software Testing&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can use JMeter to perform different types of performance testing. Let us see what types of performance testing we can do using JMeter.&lt;/p&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Load Testing&lt;/b&gt;: Already discussed above.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Volume Testing&lt;/b&gt;:&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;The main objective of volume testing in software testing is to check how well a software application works when dealing with a large amount of data. This testing helps to see how the application behaves when there is a lot of data stored in its database. It also helps find problems like system failures, slowdowns, or inefficiencies caused by handling too much data in a database or file system.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example of Volume Testing&lt;/b&gt;:&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Online ticket booking systems or banking systems process millions of transactions every hour. You can simulate these transaction&amp;nbsp;datasets to analyze the system&#39;s performance in processing a large volume of data. You can use automation tools like JMeter to perform volume testing.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Stress Testing&lt;/b&gt;:&amp;nbsp;&lt;/p&gt;&lt;p&gt;The main goal of stress testing in software testing is to observe the system&#39;s behavior in&amp;nbsp;extreme workload conditions with limited resources. You can identify the system&#39;s workload limitations and breaking or weak points when sudden spikes in user traffic,&amp;nbsp;low memory or CPU, or large data processing in a short time.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Example of Stress Testing&lt;/b&gt;&lt;/p&gt;&lt;p&gt;You can consider Netflix&#39;s global event scenario where lakhs of users start watching online streaming suddenly. You can use this scenario to simulate a sudden spike in users and observe how much stress the system can handle. You can use automation tools like Apache JMeter or&amp;nbsp;LoadRunner to perform stress testing.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Scalability Testing:&lt;/h4&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Software scalability testing determines whether the system can scale up automatically when a user&#39;s traffic or transactions increase without compromising performance or stability. It identifies resource limits and performance bottlenecks and you can plan&amp;nbsp;capacity additions accordingly&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Example of&amp;nbsp;Scalability Testing&lt;/b&gt;:&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;E-commerce sites get a large volume of users and transactions during the festival season like the Black Friday sale. You can simulate this scenario using automation tools like Apache JMeter to perform scalability testing. You can gradually increase the user base to determine the system&#39;s scalability and performance.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Spike Testing&lt;/b&gt;:&amp;nbsp;&lt;/p&gt;&lt;p&gt;Spike testing in software testing is a type of performance testing to analyze a system&#39;s performance on the sudden spike of users and how well it can recover once the spike is reduced. It can identify the system&#39;s weakness&amp;nbsp;during sudden workload changes.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Example of&amp;nbsp;Spike Testing&lt;/b&gt;:&lt;/p&gt;&lt;p&gt;Online ticket booking system&amp;nbsp;when tickets for a football or cricket go on sale before the World Cup. You can simulate this scenario to perform spike testing using automation tools like LoadRunner or Apache JMeter.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Soak Testing&lt;/b&gt;:&amp;nbsp;&lt;/p&gt;&lt;p&gt;Soak testing in software testing is known as&amp;nbsp;Endurance Testing used to determine a system&#39;s performance&amp;nbsp;under a sustained load over an extended period. It identifies the system&#39;s stability&amp;nbsp;under normal or peak load conditions over long periods.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Example of Soak Testing&lt;/b&gt;:&lt;/p&gt;&lt;p&gt;You can consider a banking system scenario&amp;nbsp;to simulate steady user transactions over a week using performance testing tools like Apache JMeter or LoadRunner.&lt;/p&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Perform Load And Performance Testing in Apache JMeter&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;To perform Apache JMeter load testing, First of all, you need to check which Java version is installed on your system. It should be&amp;nbsp;Java 8+.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Step 1. Check Java Version in Windows&lt;/b&gt;&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Type &quot;java -version&quot; in the command prompt.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNtumKxXl5TQWLNfwweR8BTY3FeqMnHeucgHMMkDU1aHgzPZd0HoiOfzzqu9mSAqvY_aP2vIblrnMDlaS8GIbiT2kZITDlsSrm_3s7ZYow26wGtlbAgIeOShsmByKJgcfs3UvYlKIt4KFwo2CrqpgENXeyCJ1Dik4zTmoSyTfp0SzQD8AqdVJ1ZaujcA3P/s613/check%20java%20version%20in%20windows.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;check java version in windows&quot; border=&quot;0&quot; data-original-height=&quot;154&quot; data-original-width=&quot;613&quot; height=&quot;80&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNtumKxXl5TQWLNfwweR8BTY3FeqMnHeucgHMMkDU1aHgzPZd0HoiOfzzqu9mSAqvY_aP2vIblrnMDlaS8GIbiT2kZITDlsSrm_3s7ZYow26wGtlbAgIeOShsmByKJgcfs3UvYlKIt4KFwo2CrqpgENXeyCJ1Dik4zTmoSyTfp0SzQD8AqdVJ1ZaujcA3P/w320-h80/check%20java%20version%20in%20windows.png&quot; title=&quot;check java version in windows&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Install or update the Java version if you do not have Java 8+ in your system.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Step 2. Download Apache JMeter Software&lt;/h4&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;To use it for testing, download the latest version of Apache JMeter software. Here is a step-by-step guide to downloading and installing jmeter.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;To download JMeter, Open&amp;nbsp;&lt;b&gt;&lt;a href=&quot;https://jmeter.apache.org/download_jmeter.cgi&quot; target=&quot;_blank&quot;&gt;JMeter Download Link&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;&lt;li&gt;Download the Zip file from the Binaries section and save it in your local drive.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjTyXXUo0QJNdvfcea4Ui2nZ8DIl4deFACOoOzG_rJbMD7k21-_lZXILX-u4L4JdQ2cyT89kO3wdHhM7aAoLfke63m0Zi_zWIqWNvwq2iWnGSzV09SqUqn9kG_Zh4usEvzDx6u7xuhxhZnjw2YLRofB_ztJeVpcTJ9J71knaYynjBmPRhijqJDlnOEogFll&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;download apache jmeter&quot; data-original-height=&quot;242&quot; data-original-width=&quot;677&quot; height=&quot;114&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjTyXXUo0QJNdvfcea4Ui2nZ8DIl4deFACOoOzG_rJbMD7k21-_lZXILX-u4L4JdQ2cyT89kO3wdHhM7aAoLfke63m0Zi_zWIqWNvwq2iWnGSzV09SqUqn9kG_Zh4usEvzDx6u7xuhxhZnjw2YLRofB_ztJeVpcTJ9J71knaYynjBmPRhijqJDlnOEogFll=w320-h114&quot; title=&quot;download apache jmeter&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Extract the downloaded JMeter folder.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;You do not need to install JMeter. You can run the jmeter.bat file from the downloaded jmeter folder to open the JMeter Interface.&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Step 3. Initiate JMeter For Testing&lt;/h4&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Open the bin folder. You will find it inside the extracted folder.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiD8ZHyNHu084arLFPQHlhETy00_UDp31T279oxQfMIoBVK7QMDsP8zGCyi0JXTN-xcen4oTqVdNZXctJw_knNcd05n-7sRRQY5dUrPDJL-ojwIfXdPCxWtCvpz9WgM1Dgw0fQukepFjXCOu_Q-y1yd3kfB1jjuW5_TacThcP78QFKIewDCpKc7s30fHZKS&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;open jmeter batch file to initiate apache jmeter&quot; data-original-height=&quot;195&quot; data-original-width=&quot;629&quot; height=&quot;99&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiD8ZHyNHu084arLFPQHlhETy00_UDp31T279oxQfMIoBVK7QMDsP8zGCyi0JXTN-xcen4oTqVdNZXctJw_knNcd05n-7sRRQY5dUrPDJL-ojwIfXdPCxWtCvpz9WgM1Dgw0fQukepFjXCOu_Q-y1yd3kfB1jjuW5_TacThcP78QFKIewDCpKc7s30fHZKS=w320-h99&quot; title=&quot;open jmeter batch file to initiate apache jmeter&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Double-click on the &quot;jmeter.bat&quot; file. It will initiate the it&#39;s interface.&lt;/li&gt;&lt;li&gt;Hold on. It can take some time to initiate the interface.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg0RUXWLIRDhe8OoLa8_wsUurqaKHdfWCL9o3bI6nF6xaEx4TSnaeO37-JBQSmTt6AWFe_v0majXCi1Hhtd8qv3_iGIHqDPln-v-DXClW9OqApOdYgrIHS8U10h54dnL-x2mruf-v0T4E_nakaGrKVCgLho1BdGf57io5wdt78YGPpdR3jvwUVL-PtiTFRu&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;open apache jmeter software from bin folder&quot; data-original-height=&quot;605&quot; data-original-width=&quot;1073&quot; height=&quot;180&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg0RUXWLIRDhe8OoLa8_wsUurqaKHdfWCL9o3bI6nF6xaEx4TSnaeO37-JBQSmTt6AWFe_v0majXCi1Hhtd8qv3_iGIHqDPln-v-DXClW9OqApOdYgrIHS8U10h54dnL-x2mruf-v0T4E_nakaGrKVCgLho1BdGf57io5wdt78YGPpdR3jvwUVL-PtiTFRu=w320-h180&quot; title=&quot;open apache jmeter software from bin folder&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Step 4: Create First Load Testing Plan in Apache JMeter&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Now you are all set to create the first JMeter load or performance testing plan. We will create a sample test plan by adding different essential components. Here is a step-by-step guide to creating a sample test plan in Apache JMeter.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Create a New Test Plan&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;In the interface, Navigate and click File -&amp;gt; New.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhTKz5Xc0yZqTPAlgFUGUBXSXLXBuIMV77JMC2FoG5dSJ2ssDENiimaSQWxr3oXNBBjT2Vw7Bl6L6qZaCijAckJ-keiT1DZyXS0Fflh8ItSYeHR7bRbp42JxDAhqb4W2Nqs69AXbXxQ8nLOSbZn3vtvL6M4mVIU5Xb6yIFAyASnFN2t6QgGzO31nS9ixKiQ&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Create First Load Testing Plan in Apache JMeter&quot; data-original-height=&quot;295&quot; data-original-width=&quot;1076&quot; height=&quot;88&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhTKz5Xc0yZqTPAlgFUGUBXSXLXBuIMV77JMC2FoG5dSJ2ssDENiimaSQWxr3oXNBBjT2Vw7Bl6L6qZaCijAckJ-keiT1DZyXS0Fflh8ItSYeHR7bRbp42JxDAhqb4W2Nqs69AXbXxQ8nLOSbZn3vtvL6M4mVIU5Xb6yIFAyASnFN2t6QgGzO31nS9ixKiQ=w320-h88&quot; title=&quot;Create First Load Testing Plan in Apache JMeter&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Rename the test plan to &quot;Sample Test&quot; and click on the save button to save it at your desired location in local drives.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Add Thread Group in Apache JMeter Test Plan&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;What is &lt;b&gt;&lt;a href=&quot;https://www.software-testing-tutorials-automation.com/2013/06/apache-jmeter-introduction-of-thread.html#google_vignette&quot; target=&quot;_blank&quot;&gt;Thread Group&lt;/a&gt;&lt;/b&gt; in JMeter?&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;It is group control in Apache JMeter. You can specify how many number of threads you want to use to execute your Apache JMeter load test. Also, you can set the Ramp-up period and loop count in a thread group.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Right-click on JMeter &quot;Sample Test&quot; plan and click on Add -&amp;gt; Threads (Users) -&amp;gt; Thread Group.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjLr31ZnOAX1w1bzTDxe2GQFC2uRstYr_spzkz2eP0dBqLFnKzbT9K1LSoD45f-BS2MlKIf4lXyhFP1UR7vI8E-pEGGb5dk8DU85uNucnWNUM3GCdKk5AfbzCSrwT8qlwUKYOFBnsgddqrtJMx45QFVxDyDOZ8IE151NdZX1qw3jtAx-UePydurXHSZeiKb&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Add thread group in jmeter test plan&quot; data-original-height=&quot;370&quot; data-original-width=&quot;1081&quot; height=&quot;110&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjLr31ZnOAX1w1bzTDxe2GQFC2uRstYr_spzkz2eP0dBqLFnKzbT9K1LSoD45f-BS2MlKIf4lXyhFP1UR7vI8E-pEGGb5dk8DU85uNucnWNUM3GCdKk5AfbzCSrwT8qlwUKYOFBnsgddqrtJMx45QFVxDyDOZ8IE151NdZX1qw3jtAx-UePydurXHSZeiKb=w320-h110&quot; title=&quot;Add thread group in jmeter test plan&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;It will add a thread group under the sample test plan.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Configure Thread Group Elements&lt;/h4&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;You need to configure the thread group to run the test with concurrent users.&lt;/li&gt;&lt;li&gt;Select Thread Group from the tree and set&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Number of Threads (users) = 5&lt;/li&gt;&lt;li&gt;Ramp-up period (seconds) = 5&lt;/li&gt;&lt;li&gt;Loop Count = 1&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;This configuration will load 5 concurrent users in 5 seconds when you run the test.&lt;/li&gt;&lt;li&gt;Save the test plan.&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEigju6We5L0twk6GictzVs4bCOeb5qwZRUG4HVU14_lJYnY_dUwVn1ybuqpVLO8VWmWQIBs0lgo6x-XQZCIa9K56zvvEfsmZlLDUJQfq8H0DhZVyhbbcQxW-sKqGt6DaQKA68Dr1zQDMRDiCPc8fI0g_bKydtt_RANykI3raSye7GdcrTqwhV2lixdIIqgm&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Configure Thread Group Elements&quot; data-original-height=&quot;551&quot; data-original-width=&quot;1011&quot; height=&quot;174&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEigju6We5L0twk6GictzVs4bCOeb5qwZRUG4HVU14_lJYnY_dUwVn1ybuqpVLO8VWmWQIBs0lgo6x-XQZCIa9K56zvvEfsmZlLDUJQfq8H0DhZVyhbbcQxW-sKqGt6DaQKA68Dr1zQDMRDiCPc8fI0g_bKydtt_RANykI3raSye7GdcrTqwhV2lixdIIqgm=w320-h174&quot; title=&quot;Configure Thread Group Elements&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Add HTTP Request&amp;nbsp;in Apache JMeter Performance Testing Plan&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;What is HTTP Request in Apache JMeter?&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;HTTP Request is a sampler in Apache JMeter. It can send HTTP or HTTPS requests to the server.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Right-click on Thread Group and select Add -&amp;gt; Sampler -&amp;gt; HTTP Request.&lt;/li&gt;&lt;li&gt;It will add an HTTP Request under Thread Group.&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiGHy-cTPbObPzazg2a6SaDC5sEmUmdCPxY17bRTuvD-zll3LwWr6Mu8vTp8AZG1730_OjZKcp-aihUG7YdK9AlgcLkmeRcy9AKBkvCoBtD1Ksdv1EMzmABzMhFepgmC0dzgyYuGc3aN9ySoB7Jfq1-cDtMFKjpILVhwCaJGq4Ew-Q9MTIJce3OerkDnJin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Add HTTP request under jmeter thread group&quot; data-original-height=&quot;595&quot; data-original-width=&quot;907&quot; height=&quot;210&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiGHy-cTPbObPzazg2a6SaDC5sEmUmdCPxY17bRTuvD-zll3LwWr6Mu8vTp8AZG1730_OjZKcp-aihUG7YdK9AlgcLkmeRcy9AKBkvCoBtD1Ksdv1EMzmABzMhFepgmC0dzgyYuGc3aN9ySoB7Jfq1-cDtMFKjpILVhwCaJGq4Ew-Q9MTIJce3OerkDnJin=w320-h210&quot; title=&quot;Add HTTP request under jmeter thread group&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h4 style=&quot;clear: both; text-align: left;&quot;&gt;Configure HTTP Request Elements&lt;/h4&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Select&amp;nbsp; HTTP Request from the tree and set&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Name = Home Page&lt;/li&gt;&lt;li&gt;Server Name or IP = Paste your website to test URL without HTTP/HTTPS&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Example&lt;/b&gt;: If your site URL is https://www.yoursitename.com/ then use only www.yoursitename.com&lt;/li&gt;&lt;li&gt;Path = /&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Save the test plan.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjQEzdvgSH2Jpu0QWCIiy2ucHQ3FpoII58MIGNBTxuOpMdC33fR0Dyy3g4ypWlNzr1ba_yxvvdM5FjDx36jIKif2uYWHwOFq6Dx7Rfh6hDbMzQlDWyxVIiXoBsbyS1Pbdpv3Zq9TLE8xPwzCpeDsaQw2VzbUk7bzBtbIlOnBidFw3HRaQwiBLPBx20eRXC-&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Configure HTTP Request Elements&quot; data-original-height=&quot;453&quot; data-original-width=&quot;1365&quot; height=&quot;106&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjQEzdvgSH2Jpu0QWCIiy2ucHQ3FpoII58MIGNBTxuOpMdC33fR0Dyy3g4ypWlNzr1ba_yxvvdM5FjDx36jIKif2uYWHwOFq6Dx7Rfh6hDbMzQlDWyxVIiXoBsbyS1Pbdpv3Zq9TLE8xPwzCpeDsaQw2VzbUk7bzBtbIlOnBidFw3HRaQwiBLPBx20eRXC-=w320-h106&quot; title=&quot;Configure HTTP Request Elements&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can add multiple requests as well under the thread group to execute all of them&amp;nbsp;simultaneously.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Add Listeners in Apache JMeter Load Testing Plan&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;What is Listeners in Apache JMeter?&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Listeners are used to displaying the results of your&amp;nbsp;jmeter performance tests. There are different types of listeners available in Apache JMeter. You can add them as per your requirements.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Right-click on Thread Group -&amp;gt; Add -&amp;gt; Listener -&amp;gt;&amp;nbsp;View Results Tree.&lt;/li&gt;&lt;li&gt;Right-click on Thread Group -&amp;gt; Add -&amp;gt; Listener -&amp;gt; Summary Report.&lt;/li&gt;&lt;li&gt;It will add both listeners under the test plan tree.&lt;/li&gt;&lt;li&gt;Save sample load testing plan.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEh5TS1QElkEdI2awzJZE07n8RPkdfRlbsVk-cLchl6IjZAjTasZediKOwmStjNj79Pak_WSbSqUDuMNv2ffi6jH2mVqrz9rfwws3W_BAAwCw32xTHAPEBFJig6sQR31Ehi8xYPcjmxWVp3LgShucSTbWEhRgTVzpCmyjuDcI-L2coEXM73m36Ej46udvIu9&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Add Listeners in Apache JMeter Load Testing Plan&quot; data-original-height=&quot;647&quot; data-original-width=&quot;909&quot; height=&quot;228&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEh5TS1QElkEdI2awzJZE07n8RPkdfRlbsVk-cLchl6IjZAjTasZediKOwmStjNj79Pak_WSbSqUDuMNv2ffi6jH2mVqrz9rfwws3W_BAAwCw32xTHAPEBFJig6sQR31Ehi8xYPcjmxWVp3LgShucSTbWEhRgTVzpCmyjuDcI-L2coEXM73m36Ej46udvIu9=w320-h228&quot; title=&quot;Add Listeners in Apache JMeter Load Testing Plan&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;You can add any other samplers as well as per your testing requirement.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Now sample performance test plan is ready to run.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Step 5: Run Apache Jmeter Sample Load Test Plan&lt;/h4&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;Now you can Run your sample test plan.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;You can Run a test plan by&amp;nbsp;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Clicking on the Start button or&lt;/li&gt;&lt;li&gt;Selecting menu Run -&amp;gt; Start.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhpkOTpoDnDDTBrcFD8Pgl-GXe-7slmRxJ-uOZJyE0LWfcxnX4Tz5UaVjpGmbwX2j1F5KirxvYgJOyC7CdhYv1R8Igp25E-baEYsQi8YS0suvVhm_nPMFjIQpr8tuR_qT-2hqKysY0jG4tvH69SJxP538tV4MOb98aqEQiPwpL_6NyaMxxLdjRBHdfxWWvV&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Run Apache Jmeter Sample Load Test Plan&quot; data-original-height=&quot;251&quot; data-original-width=&quot;838&quot; height=&quot;96&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhpkOTpoDnDDTBrcFD8Pgl-GXe-7slmRxJ-uOZJyE0LWfcxnX4Tz5UaVjpGmbwX2j1F5KirxvYgJOyC7CdhYv1R8Igp25E-baEYsQi8YS0suvVhm_nPMFjIQpr8tuR_qT-2hqKysY0jG4tvH69SJxP538tV4MOb98aqEQiPwpL_6NyaMxxLdjRBHdfxWWvV=w320-h96&quot; title=&quot;Run Apache Jmeter Sample Load Test Plan&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Our sample test plan will be executed with 5 concurrent threads (users) as per our Thread group configuration. It will loan 1 thread per second. Select View Result Tree listener during test execution to see how users are loaded to execute requests. You can increase the number of threads or Ramp up the period as per your requirement for more clarity.&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Step 6: View Test Results&lt;/h4&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Load test results will be displayed in Listeners. You can view results by selecting both listeners one by one as below.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEi3gX9BbUGRy6_OgOUqZISKJbzl43VWCGbMqf6wE5DhTltM0XFirN3Vv3nuuBivuBTP32iMC1IFMLrNDtFof0LhS-BdMeuA_O0XSo8j0gTRDA-2kyh1M6yV3cbJCM6IngA4z059yRbyryPXiJ6GjaW3Fvg5jyvhzPBMvJ8qxpfRx7D-V7YkJnjnuopCUAuA&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;View Apache JMeter Test Results&quot; data-original-height=&quot;903&quot; data-original-width=&quot;1343&quot; height=&quot;215&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEi3gX9BbUGRy6_OgOUqZISKJbzl43VWCGbMqf6wE5DhTltM0XFirN3Vv3nuuBivuBTP32iMC1IFMLrNDtFof0LhS-BdMeuA_O0XSo8j0gTRDA-2kyh1M6yV3cbJCM6IngA4z059yRbyryPXiJ6GjaW3Fvg5jyvhzPBMvJ8qxpfRx7D-V7YkJnjnuopCUAuA=w320-h215&quot; title=&quot;View Apache JMeter Test Results&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Conclusion&lt;/h2&gt;Apache JMeter is a powerful, open-source tool that simplifies load and performance testing for businesses. As a cornerstone in software testing, JMeter empowers organizations to ensure their applications are reliable, efficient, and scalable under various conditions. Its features make JMeter software ideal for detecting performance bottlenecks, enhancing user experience, and maintaining system stability. By using JMeter for testing, businesses can gain valuable insights into optimizing performance. Whether focusing on Apache JMeter load testing to handle user traffic or JMeter performance testing to ensure speed and reliability, this versatile tool is a must-have for successful application development and maintenance.</description><link>http://software-testing-tutorials-automation.blogspot.com/2025/01/apache-jmeter-load-and-performance.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUIG4j7iWHgasJ4f3ABWiacw-8FroO6P_5SV9nuYjhA6eKLjJTpt-cmcnvY4rT0lOiViHLZKQ1F6qHcFxCUbfpOwnb_qctOAlnWaJdLTFqHfccS5hjz96o71fN9oYTOpYJoQNOItZVYTONCXsoFBngS6AdzGPfaMe4XVzVWHlwP9a_xBLWde1DZh8QGUCA/s72-w320-h320-c/Apache%20JMeter%20for%20load%20and%20performance%20testing.webp" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-5278661109579213932</guid><pubDate>Tue, 06 Dec 2022 04:30:00 +0000</pubDate><atom:updated>2022-12-05T20:39:03.014-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">selenium</category><category domain="http://www.blogger.com/atom/ns#">selenium 4</category><category domain="http://www.blogger.com/atom/ns#">selenium tutorial</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver tutorial</category><title>Getsize In Selenium</title><description>&lt;h2 style=&quot;text-align: justify;&quot;&gt;Selenium getSize() method&lt;/h2&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can get the browser window size using getSize() method in selenium. It will be helpful to get the current working window size(height &amp;amp; width) in selenium test execution if required.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;getSize() method in selenium is part of&amp;nbsp;WebDriver.Window interface.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;It is used when you want to get current working window dimensions.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;It will return height and width of current working browser window.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;Syntax :&amp;nbsp;driver.manage().window().getSize();&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-nNHA_LiwnE3EpZJ8xMp8nOwE_Zs7gsVj0L7TRWS9Rogf3wmEwiVHVS7teScjr58Q83zcWapN1LxJh9TRaVKaT-rKpkUbZdoCV3CMrnONOC2J2IcDdoF4xYLDkqI8lgejcAp2aXw9vgL1SU4b9XtYaAEQfbhm7nLnzZKNeQaq23AVKeYXu_SS6qkX3g/s799/Selenium%20getsize()%20method.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Selenium getsize() method&quot; border=&quot;0&quot; data-original-height=&quot;415&quot; data-original-width=&quot;799&quot; height=&quot;208&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-nNHA_LiwnE3EpZJ8xMp8nOwE_Zs7gsVj0L7TRWS9Rogf3wmEwiVHVS7teScjr58Q83zcWapN1LxJh9TRaVKaT-rKpkUbZdoCV3CMrnONOC2J2IcDdoF4xYLDkqI8lgejcAp2aXw9vgL1SU4b9XtYaAEQfbhm7nLnzZKNeQaq23AVKeYXu_SS6qkX3g/w400-h208/Selenium%20getsize()%20method.png&quot; title=&quot;Selenium getsize() method&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Let us see how getSize() method works to get browser window dimension with example.&lt;/p&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;Selenium getSize() method example to get window size&lt;/h3&gt;&lt;div&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; background: #f0f0f0; border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;package testPackage;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class getsizeExample{

	public static void main(String[] args) {
				
		System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;D:\\chromedriver.exe&quot;);
		WebDriver driver=new ChromeDriver();		
		//Get current window size dimension and print it in console.	
		Dimension size = driver.manage().window().getSize();
		System.out.println(size);
	}
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;In above given example, getsize() method will return height and width of current launched window and it will print it in console.&lt;/p&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2022/12/getsize-in-selenium.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-nNHA_LiwnE3EpZJ8xMp8nOwE_Zs7gsVj0L7TRWS9Rogf3wmEwiVHVS7teScjr58Q83zcWapN1LxJh9TRaVKaT-rKpkUbZdoCV3CMrnONOC2J2IcDdoF4xYLDkqI8lgejcAp2aXw9vgL1SU4b9XtYaAEQfbhm7nLnzZKNeQaq23AVKeYXu_SS6qkX3g/s72-w400-h208-c/Selenium%20getsize()%20method.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-8362792227172244628</guid><pubDate>Tue, 06 Dec 2022 03:43:00 +0000</pubDate><atom:updated>2022-12-05T20:38:44.469-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">selenium</category><category domain="http://www.blogger.com/atom/ns#">selenium 4</category><category domain="http://www.blogger.com/atom/ns#">selenium tutorial</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver tutorial</category><title>Selenium Set Window Size</title><description>&lt;h2 style=&quot;text-align: justify;&quot;&gt;Set browser window size in selenium&lt;/h2&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Selenium has built in method to set size of browser window. You can use&amp;nbsp;setSize() method to set the browser window size during your selenium test execution. This method is useful when you want to resize the browser window as per your selenium test requirement.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;setSize() method is part of&amp;nbsp;WebDriver.Window interface.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;This method&#39;s return type is void.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;You can provide the size of window to set set size of current working window in selenium test.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;Syntax :&amp;nbsp;driver.manage().window().setSize(new Dimension(w, h));&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;It will set window size as per the given dimension.&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBI8NYAy9kC7EyjVaAS6ogSZYxk7s5OXhPRaGlrIkVVaglEFWnuad6bp81solJ5ZV1hbdALwb3iKD1rq2fSIzqCnQOrOjgcJPggKGZEFKc8XIIqAIpqXPuhcWk8tQzSWRfAV13KMjRYzWh-cQJigBZ6teeoOHIkzVQiAyzBYILaF0Hda3kAZVsp4VSbg/s799/selenium%20setsize%20method.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;selenium setsize method&quot; border=&quot;0&quot; data-original-height=&quot;417&quot; data-original-width=&quot;799&quot; height=&quot;209&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBI8NYAy9kC7EyjVaAS6ogSZYxk7s5OXhPRaGlrIkVVaglEFWnuad6bp81solJ5ZV1hbdALwb3iKD1rq2fSIzqCnQOrOjgcJPggKGZEFKc8XIIqAIpqXPuhcWk8tQzSWRfAV13KMjRYzWh-cQJigBZ6teeoOHIkzVQiAyzBYILaF0Hda3kAZVsp4VSbg/w400-h209/selenium%20setsize%20method.png&quot; title=&quot;selenium setsize method&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Let us implement this method practically to see how it works.&lt;/p&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;setSize() example in selenium&lt;/h3&gt;&lt;div&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;package testPackage;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class setsizeExample{

	public static void main(String[] args) {
				
		System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;D:\\chromedriver.exe&quot;);
		WebDriver driver=new ChromeDriver();		
		//Set size of browser window as per given dimensions.	
		driver.manage().window().setSize(new Dimension(1250, 600));
		driver.navigate().to(&quot;http://only-testing-blog.blogspot.com/2013/09/testing.html&quot;);
	}
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;If you look at above given example, We have provided window size dimension to 1250 X 600. It will set browser window size as per provided dimensions.&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2022/12/selenium-set-window-size.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBI8NYAy9kC7EyjVaAS6ogSZYxk7s5OXhPRaGlrIkVVaglEFWnuad6bp81solJ5ZV1hbdALwb3iKD1rq2fSIzqCnQOrOjgcJPggKGZEFKc8XIIqAIpqXPuhcWk8tQzSWRfAV13KMjRYzWh-cQJigBZ6teeoOHIkzVQiAyzBYILaF0Hda3kAZVsp4VSbg/s72-w400-h209-c/selenium%20setsize%20method.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-7047136343713634399</guid><pubDate>Mon, 05 Dec 2022 09:31:00 +0000</pubDate><atom:updated>2022-12-05T19:19:02.455-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">selenium</category><category domain="http://www.blogger.com/atom/ns#">selenium 4</category><category domain="http://www.blogger.com/atom/ns#">selenium tutorial</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver tutorial</category><title>Selenium Window Full Screen</title><description>&lt;h2 style=&quot;text-align: left;&quot;&gt;Full Screen Window In Selenium&lt;/h2&gt;&lt;p&gt;Selenium&amp;nbsp;fullscreen() method is used to full screen the browser window. It will perform browser full screen action same as real user full screen the browser window. May be sometimes you need full screen window in your selenium tests at that time this method will be very useful for you.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;fullscreen() method is part of&amp;nbsp;WebDriver.Window interface.&lt;/li&gt;&lt;li&gt;It&#39;s return type is void so it returns nothing.&lt;/li&gt;&lt;li&gt;It will full screen the browser window.&lt;/li&gt;&lt;li&gt;Syntax :&amp;nbsp;driver.manage().window().fullscreen();&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;Below given example will show you how fullscreen() method is used to full screen the window size.&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgk3SBefnpy5QCdWP1jYPiP4TqqRL0_7r_MKFUQm3s77aNKI-9UwMiCy211cpPcz9R13woVQaWfiL_Bl-5wgqX-16T3IOJSZDLUvrPbbDpdhmWNaJryFdr6KOJvILtUmwomYrWNPPkv2ZYMKkBe5C7OclPVru0B98qIoIMua8jqMqKqO-UMyVmSKMtQ5A/s799/Selenium%20fullscreen%20method.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Selenium fullscreen method&quot; border=&quot;0&quot; data-original-height=&quot;417&quot; data-original-width=&quot;799&quot; height=&quot;209&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgk3SBefnpy5QCdWP1jYPiP4TqqRL0_7r_MKFUQm3s77aNKI-9UwMiCy211cpPcz9R13woVQaWfiL_Bl-5wgqX-16T3IOJSZDLUvrPbbDpdhmWNaJryFdr6KOJvILtUmwomYrWNPPkv2ZYMKkBe5C7OclPVru0B98qIoIMua8jqMqKqO-UMyVmSKMtQ5A/w400-h209/Selenium%20fullscreen%20method.png&quot; title=&quot;Selenium fullscreen method&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;h3&gt;Selenium fullscreen() method example&lt;/h3&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;package testPackage;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class fullscreenExample{

	public static void main(String[] args) {
				
		System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;D:\\chromedriver.exe&quot;);
		WebDriver driver=new ChromeDriver();		
		driver.navigate().to(&quot;http://only-testing-blog.blogspot.com/2013/09/testing.html&quot;);
		//Fullscreen the browser window.	
		driver.manage().window().fullscreen();		
	}
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In above given example, fullscreen() method will resize the window size to full screen.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2022/12/selenium-window-full-screen.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgk3SBefnpy5QCdWP1jYPiP4TqqRL0_7r_MKFUQm3s77aNKI-9UwMiCy211cpPcz9R13woVQaWfiL_Bl-5wgqX-16T3IOJSZDLUvrPbbDpdhmWNaJryFdr6KOJvILtUmwomYrWNPPkv2ZYMKkBe5C7OclPVru0B98qIoIMua8jqMqKqO-UMyVmSKMtQ5A/s72-w400-h209-c/Selenium%20fullscreen%20method.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-7396132961961261487</guid><pubDate>Mon, 05 Dec 2022 05:33:00 +0000</pubDate><atom:updated>2022-12-05T19:19:44.272-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">selenium</category><category domain="http://www.blogger.com/atom/ns#">selenium 4</category><category domain="http://www.blogger.com/atom/ns#">selenium tutorial</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver tutorial</category><title>Selenium Minimize Window Of Browser</title><description>&lt;h2 style=&quot;text-align: justify;&quot;&gt;Minimize window in selenium&amp;nbsp;&lt;/h2&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Selenium 4 has built in method to minimize the browser window. It is less used method in selenium but still you can use it if you want to minimize window in between selenium test. minimize() method will perform browser minimize user action. You can run your selenium tests in minimized browser mode and you can perform your other tasks beside.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;minimize() method is part of&amp;nbsp;WebDriver.Window method.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;This method will return nothing because it&#39;s return type is void.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;It will minimize the current working window if it is not already minimized.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;It is helpful when your are performing manual testing or any other work as your selenium tests will be executed in minimized mode.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;Syntax :&amp;nbsp;driver.manage().window().maximize();&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4PkvlL-V0sEP3oqjDjLvGWr8CdTmZ8up3NVz416cb-OgSxB-AeSpSSV14avFi78ERJ2iG3P-FkXLBEepnNryG55U97XcKJGn7GajvTevpiD0YQs1h7m3j8gupxWDGCiW_ezuRAyR2Skh8a2hPovz1JGK-ReYQSF3kCcKcSxrVnTv5Ux3kwfJ4h69P2w/s799/Selenium%20Minimize%20Window.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Selenium Minimize Window using minimize() method&quot; border=&quot;0&quot; data-original-height=&quot;413&quot; data-original-width=&quot;799&quot; height=&quot;206&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4PkvlL-V0sEP3oqjDjLvGWr8CdTmZ8up3NVz416cb-OgSxB-AeSpSSV14avFi78ERJ2iG3P-FkXLBEepnNryG55U97XcKJGn7GajvTevpiD0YQs1h7m3j8gupxWDGCiW_ezuRAyR2Skh8a2hPovz1JGK-ReYQSF3kCcKcSxrVnTv5Ux3kwfJ4h69P2w/w400-h206/Selenium%20Minimize%20Window.png&quot; title=&quot;Selenium Minimize Window using minimize() method&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Let us see practical example of using minimize() method in selenium.&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;Selenium minimize() method example&lt;/h3&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;package testPackage;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class maximizewindowExample {

	public static void main(String[] args) {
				
		System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;D:\\chromedriver.exe&quot;);
		WebDriver driver=new ChromeDriver();
		//Minimize the browser window.		
		driver.manage().window().minimize();
		
		driver.navigate().to(&quot;http://only-testing-blog.blogspot.com/2013/09/testing.html&quot;);
		driver.findElement(By.xpath(&quot;//span[normalize-space()=&#39;Test Link&#39;]&quot;)).click();
		driver.manage().window().maximize();
	}
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;In above given example, minimize() method will minimize the chrome browser window.&lt;/p&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2022/12/selenium-minimize-window-of-browser.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4PkvlL-V0sEP3oqjDjLvGWr8CdTmZ8up3NVz416cb-OgSxB-AeSpSSV14avFi78ERJ2iG3P-FkXLBEepnNryG55U97XcKJGn7GajvTevpiD0YQs1h7m3j8gupxWDGCiW_ezuRAyR2Skh8a2hPovz1JGK-ReYQSF3kCcKcSxrVnTv5Ux3kwfJ4h69P2w/s72-w400-h206-c/Selenium%20Minimize%20Window.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-5512659541922065048</guid><pubDate>Mon, 05 Dec 2022 04:10:00 +0000</pubDate><atom:updated>2022-12-05T19:20:08.230-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">selenium</category><category domain="http://www.blogger.com/atom/ns#">selenium 4</category><category domain="http://www.blogger.com/atom/ns#">selenium tutorial</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver tutorial</category><title>Selenium Maximize Window Of Browser</title><description>&lt;h2 style=&quot;text-align: justify;&quot;&gt;Maximize window in selenium&lt;/h2&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can maximize window in selenium using maximize() method. Every time you launch browser in selenium test, It will open browser window in small size. So maximize() is most commonly used method in selenium test scripts. Maximize() method works same as user click on browser maximize icon to maximize the window. Selenium test scripts can be run without maximizing windows as well but it is good practice to maximizing browser windows before running the tests on page.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2MYrF6FplO8V0VrFRpCQBAox23J6I-cU7wPFDHOvCv7En4pKKvg829ZxXZkiRCOaBhZ8HKypMJRcIcJEdZ-IL41vXZ95s5Qw4m2zQflWF5g2G8GuAY8OVXXa5D0zYE69VbNSf4FL8rUzX4_jf77JjfrG0eRWhApGttqBy9Tx1Gkj3fsvL82z4xYk74Q/s800/selenium%20maximize()%20method.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;selenium maximize() method&quot; border=&quot;0&quot; data-original-height=&quot;414&quot; data-original-width=&quot;800&quot; height=&quot;208&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2MYrF6FplO8V0VrFRpCQBAox23J6I-cU7wPFDHOvCv7En4pKKvg829ZxXZkiRCOaBhZ8HKypMJRcIcJEdZ-IL41vXZ95s5Qw4m2zQflWF5g2G8GuAY8OVXXa5D0zYE69VbNSf4FL8rUzX4_jf77JjfrG0eRWhApGttqBy9Tx1Gkj3fsvL82z4xYk74Q/w400-h208/selenium%20maximize()%20method.png&quot; title=&quot;selenium maximize() method&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;Maximize() method in selenium is part of&amp;nbsp;WebDriver.Window interface.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;It&#39;s return type is void.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;It will maximize the current working browser window if it is not already maximized.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;This method is generally used just after launching the browser window in selenium test script.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;Syntax :&amp;nbsp;driver.manage().window().maximize();&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Let us see practical example to maximize the browser window in selenium test.&lt;/div&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;Selenium window maximize() example&lt;/h3&gt;
  &lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;package testPackage;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class maximizewindowExample {

	public static void main(String[] args) {
				
		System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;D:\\chromedriver.exe&quot;);
		WebDriver driver=new ChromeDriver();
		//Maximize the browser window.
		driver.manage().window().maximize();
		
		driver.navigate().to(&quot;http://only-testing-blog.blogspot.com/2013/09/testing.html&quot;);
	}
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;In above given example, we have used maximize() method after launching the browser. So initially browser will be launched and then maximize() method will maximize the browser window.&lt;/p&gt;&lt;/div&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2022/12/selenium-maximize-window.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2MYrF6FplO8V0VrFRpCQBAox23J6I-cU7wPFDHOvCv7En4pKKvg829ZxXZkiRCOaBhZ8HKypMJRcIcJEdZ-IL41vXZ95s5Qw4m2zQflWF5g2G8GuAY8OVXXa5D0zYE69VbNSf4FL8rUzX4_jf77JjfrG0eRWhApGttqBy9Tx1Gkj3fsvL82z4xYk74Q/s72-w400-h208-c/selenium%20maximize()%20method.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-8127616112194534051</guid><pubDate>Fri, 02 Dec 2022 10:20:00 +0000</pubDate><atom:updated>2022-12-04T20:28:51.812-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">selenium</category><category domain="http://www.blogger.com/atom/ns#">selenium 4</category><category domain="http://www.blogger.com/atom/ns#">selenium tutorial</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver tutorial</category><title>Selenium get url using getCurrentUrl()</title><description>&lt;h2 style=&quot;text-align: justify;&quot;&gt;Get url in selenium using getCurrentUrl() Method&lt;/h2&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Sometimes you need to get the current url during selenium test. You can get the URL of current open page using getCurrentUrl() method in selenium.&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;getCurrentUrl() method is part of WebDriver interface which extends SearchContext interface.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;It will fetch the url from current open page in browser.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;It will return rul as a string.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;Syntax to use getCurrentUrl() : driver.getCurrentUrl().&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Below given example will show you how to get url of current open page using getCurrentUrl() method in selenium.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjQECzdCaVYTNZ4FkHYAQptqVFpQsUpjdRk11CaCoZatKS7ihAujbyyrV5Ue2AHFEgkUY3sEm4kx8rdiJ_0qM4krHP8Q4JSPS0MqB3l4cTryOos3wRuCnvoTFjzbrznIQChVWoiG7g-oZumzzewVODRmQEzGqyKea7UeGP-Hkh9lBoN0zLNoSq1SV_QQ/s799/Selenium%20getCurrentUrl()%20Method.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Selenium getCurrentUrl() Method&quot; border=&quot;0&quot; data-original-height=&quot;417&quot; data-original-width=&quot;799&quot; height=&quot;209&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjQECzdCaVYTNZ4FkHYAQptqVFpQsUpjdRk11CaCoZatKS7ihAujbyyrV5Ue2AHFEgkUY3sEm4kx8rdiJ_0qM4krHP8Q4JSPS0MqB3l4cTryOos3wRuCnvoTFjzbrznIQChVWoiG7g-oZumzzewVODRmQEzGqyKea7UeGP-Hkh9lBoN0zLNoSq1SV_QQ/w400-h209/Selenium%20getCurrentUrl()%20Method.png&quot; title=&quot;Selenium getCurrentUrl() Method&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;Selenium getCurrentUrl() method example&lt;/h3&gt;
  &lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; background: #f0f0f0; border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;package testPackage;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class getCurrentUrlExample {

	public static void main(String[] args) {
				
		System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;D:\\chromedriver.exe&quot;);
		WebDriver driver=new ChromeDriver();
		
		driver.navigate().to(&quot;http://only-testing-blog.blogspot.com/2013/09/testing.html&quot;);
		
		//Get current url of page and print it in console.
		String url = driver.getCurrentUrl();
		System.out.println(&quot;Current URL is : &quot;+url);
	}
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In above given example, getCurrentUrl() method will fetch url string of page and print it in console.&lt;/div&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2022/12/selenium-get-url-using-getcurrenturl.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjQECzdCaVYTNZ4FkHYAQptqVFpQsUpjdRk11CaCoZatKS7ihAujbyyrV5Ue2AHFEgkUY3sEm4kx8rdiJ_0qM4krHP8Q4JSPS0MqB3l4cTryOos3wRuCnvoTFjzbrznIQChVWoiG7g-oZumzzewVODRmQEzGqyKea7UeGP-Hkh9lBoN0zLNoSq1SV_QQ/s72-w400-h209-c/Selenium%20getCurrentUrl()%20Method.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-8225348326247457159</guid><pubDate>Thu, 01 Dec 2022 11:08:00 +0000</pubDate><atom:updated>2022-12-01T03:08:27.901-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">selenium</category><category domain="http://www.blogger.com/atom/ns#">selenium 4</category><category domain="http://www.blogger.com/atom/ns#">selenium tutorial</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver tutorial</category><title>Selenium close browser</title><description>&lt;h2 style=&quot;text-align: justify;&quot;&gt;Close browser in selenium using close() method&lt;/h2&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;To close browser in selenium, You can use close() method. It is used to close current open window on which selenium test is being executed.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;close() method is part of WebDriver interface which extends&amp;nbsp;SearchContext interface.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;close() method in selenium will close only current selected window.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;If multiple browser windows are open in selenium test then all windows will be not closed using close() method.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;Syntax for using close() method is driver.close();&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5BfKUCkcuW88MTsun0D8gcQZB69xDo2aMybNvNpGxIIXAdvAYBrCXH8U2qkrx8MfMzQhcq0CE6k86FDgI28QYnz8uc9wOfQzHnXDpIFmpM9A6bDc6AIWkEt49wo5hRPgOewYOxKrZV8zwo479NlseiAsTCtneFR1DAX5bJIezmJyc-6RESopvkpDV0A/s799/Selenium%20Close()%20Method.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Selenium Close() Method&quot; border=&quot;0&quot; data-original-height=&quot;415&quot; data-original-width=&quot;799&quot; height=&quot;208&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5BfKUCkcuW88MTsun0D8gcQZB69xDo2aMybNvNpGxIIXAdvAYBrCXH8U2qkrx8MfMzQhcq0CE6k86FDgI28QYnz8uc9wOfQzHnXDpIFmpM9A6bDc6AIWkEt49wo5hRPgOewYOxKrZV8zwo479NlseiAsTCtneFR1DAX5bJIezmJyc-6RESopvkpDV0A/w400-h208/Selenium%20Close()%20Method.png&quot; title=&quot;Selenium Close() Method&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;Selenium close() method example&lt;/h3&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; background: #f0f0f0; border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;package testPackage;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class getTitleExample {

	public static void main(String[] args) {
				
		System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;D:\\chromedriver.exe&quot;);
		WebDriver driver=new ChromeDriver();
		
		driver.navigate().to(&quot;http://only-testing-blog.blogspot.com/2013/09/testing.html&quot;);
		
		//close current running driver instance.		
		driver.close();		
	}
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;In above given example, close() method will close the current running driver window.&lt;/p&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2022/12/selenium-close-browser.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5BfKUCkcuW88MTsun0D8gcQZB69xDo2aMybNvNpGxIIXAdvAYBrCXH8U2qkrx8MfMzQhcq0CE6k86FDgI28QYnz8uc9wOfQzHnXDpIFmpM9A6bDc6AIWkEt49wo5hRPgOewYOxKrZV8zwo479NlseiAsTCtneFR1DAX5bJIezmJyc-6RESopvkpDV0A/s72-w400-h208-c/Selenium%20Close()%20Method.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-6553795379765080684</guid><pubDate>Thu, 01 Dec 2022 03:54:00 +0000</pubDate><atom:updated>2022-12-01T03:10:42.656-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">selenium</category><category domain="http://www.blogger.com/atom/ns#">selenium 4</category><category domain="http://www.blogger.com/atom/ns#">selenium tutorial</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver tutorial</category><title>Selenium getTitle() method to get title of page</title><description>&lt;h2 style=&quot;text-align: justify;&quot;&gt;Selenium get title using getTitle() method&lt;/h2&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;If you view source of page, You will find title of the page inside &amp;lt;title&amp;gt; and &amp;lt;/title&amp;gt; tags. Selenium getTitle() method is useful to get the title of the page. You can verify or assert that title in selenium test case to check if targeted page is open or not.&lt;/div&gt;&lt;div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;getTitle() method is part of WebDriver interface which extends&amp;nbsp;SearchContext interface.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;It will return title of the web page if title is available for page.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;It will return null string if title of the page is missing.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;Syntax to get title :&amp;nbsp;driver.getTitle();&lt;/li&gt;&lt;/ol&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizQSf8W44wnAabXjTjbPeZ6QGElTdqCS0GDkAmg8-DN1wLlJAQufZKiYRDN8ey5LOSCmsc8mhVwMDhE68y-Tp5uSQWKiMzeiVSbElqPO_zryyrBFydt-GfKB8KOqSW3Mt565WES1dHi0FKfSIFMf1k0pSsB38FJiAXRL7Ec8-8Bcb6tnQlNQUAEg5ZQQ/s799/Selenium%20getTitle()%20Method.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Selenium getTitle() Method&quot; border=&quot;0&quot; data-original-height=&quot;417&quot; data-original-width=&quot;799&quot; height=&quot;209&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizQSf8W44wnAabXjTjbPeZ6QGElTdqCS0GDkAmg8-DN1wLlJAQufZKiYRDN8ey5LOSCmsc8mhVwMDhE68y-Tp5uSQWKiMzeiVSbElqPO_zryyrBFydt-GfKB8KOqSW3Mt565WES1dHi0FKfSIFMf1k0pSsB38FJiAXRL7Ec8-8Bcb6tnQlNQUAEg5ZQQ/w400-h209/Selenium%20getTitle()%20Method.png&quot; title=&quot;Selenium getTitle() Method&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;Example of selenium getTitle() method&lt;/h3&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;In below given example, We will open test site page and get the title. We will print that title in console.&lt;/p&gt;&lt;div&gt;

&lt;pre  style=&#39;font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;&#39;&gt;&lt;code style=&#39;color:#000000;word-wrap:normal;&#39;&gt;package testPackage;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class getTitleExample {

	public static void main(String[] args) {
				
		System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;D:\\chromedriver.exe&quot;);
		WebDriver driver=new ChromeDriver();
		
		driver.navigate().to(&quot;http://www.only-testing-blog.blogspot.com&quot;);
		
		//Get the title of page and print it in console.
		String pageTitle = driver.getTitle();
		System.out.println(&quot;Page title is : &quot;+pageTitle);	
	}
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;In console, It will print the title of the web page.&lt;/p&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2022/11/selenium-gettitle-method-to-get-title.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizQSf8W44wnAabXjTjbPeZ6QGElTdqCS0GDkAmg8-DN1wLlJAQufZKiYRDN8ey5LOSCmsc8mhVwMDhE68y-Tp5uSQWKiMzeiVSbElqPO_zryyrBFydt-GfKB8KOqSW3Mt565WES1dHi0FKfSIFMf1k0pSsB38FJiAXRL7Ec8-8Bcb6tnQlNQUAEg5ZQQ/s72-w400-h209-c/Selenium%20getTitle()%20Method.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2973787519736718861.post-5254015759684735006</guid><pubDate>Wed, 30 Nov 2022 06:06:00 +0000</pubDate><atom:updated>2022-11-29T22:06:29.803-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">selenium</category><category domain="http://www.blogger.com/atom/ns#">selenium 4</category><category domain="http://www.blogger.com/atom/ns#">selenium tutorial</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver</category><category domain="http://www.blogger.com/atom/ns#">selenium webdriver tutorial</category><title>Selenium get attribute to get value of attribute</title><description>&lt;h2 style=&quot;text-align: justify;&quot;&gt;Selenium getAttribute() method&lt;/h2&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can get value of attribute using getAttribute() method in selenium. As you know, all the web elements have one to many attributes. Sometimes you need to get it&#39;s value in selenium test to use it somewhere. At that time, selenium&#39;s build in getAttribute method will help to get value of that specific attribute.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTKGbunhb1vn6AleTTbOlDGmiiL0EqBlg4YMeIq-9D38ae53q7EC1dKnzcoAIeBP0KjiRpg88_wHUg31PsiUpIM-x4unuNkPzJZDyOPsgutRRqQ_sHmxx7duzEVdp2fM76sTwh7u4GXYCp4k52E8mFb-OtZ7TeFG3qCavsnV5F0AQrmy1j8xmXKSukyQ/s799/Selenium%20getAttribute()%20method.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Selenium getAttribute() method&quot; border=&quot;0&quot; data-original-height=&quot;415&quot; data-original-width=&quot;799&quot; height=&quot;208&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTKGbunhb1vn6AleTTbOlDGmiiL0EqBlg4YMeIq-9D38ae53q7EC1dKnzcoAIeBP0KjiRpg88_wHUg31PsiUpIM-x4unuNkPzJZDyOPsgutRRqQ_sHmxx7duzEVdp2fM76sTwh7u4GXYCp4k52E8mFb-OtZ7TeFG3qCavsnV5F0AQrmy1j8xmXKSukyQ/w400-h208/Selenium%20getAttribute()%20method.png&quot; title=&quot;Selenium getAttribute() method&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;getAttribute() method is part of WebElement interface which extends&amp;nbsp;SearchContext and TakesScreenshot interfaces.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;getAttribute() method is used to get value of that specific attribute of an element.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;It will return value of attribute if attribute found.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;It will return empty string if attribute not found.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;Syntax for getAttribute() method :&amp;nbsp;driver.findElement(By.Element_locator).getAttribute(Attribute_name);&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In order to get value of element&#39;s attribute, First of all you need to locate that element. Then you can provide name of attribute inside getAttribute method to get it&#39;s value. Let us see it with practical example.&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;getAttribute() method example&lt;/h3&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLo2W4t9GpzlaRcbeE_Rmym2CwPqOHPv2SWQNAChZSXIef1nKCgaT1dDNNrg8oIIhUGJzBoofCEZK7h4gVCigNg-5BxGBgM0BclVAolqx2DMeBgHfAUJhQSA_jG8uklhP-YZp9vVGXrt2PKJpaEr_EPKtTCgszGWmNwA-NNzVv5v8Fu13g-1t_Fws1xA/s696/selenium%20getattribute%20method.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Selenium getattribute() method&quot; border=&quot;0&quot; data-original-height=&quot;483&quot; data-original-width=&quot;696&quot; height=&quot;278&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLo2W4t9GpzlaRcbeE_Rmym2CwPqOHPv2SWQNAChZSXIef1nKCgaT1dDNNrg8oIIhUGJzBoofCEZK7h4gVCigNg-5BxGBgM0BclVAolqx2DMeBgHfAUJhQSA_jG8uklhP-YZp9vVGXrt2PKJpaEr_EPKtTCgszGWmNwA-NNzVv5v8Fu13g-1t_Fws1xA/w400-h278/selenium%20getattribute%20method.png&quot; title=&quot;Selenium getattribute() method&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;In above given image, element Grand Parent1 have total 3 attributes id, name and type. We will locate that element by id and then try to get it&#39;s name and type attribute&#39;s values.&lt;/p&gt;&lt;div&gt;
&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS5pqHwvmikMoMPdCPkVAdJInpGgtOcFd-xMlnuv-OQ4WBjRZh3-7PWn7rlk2qNa1whTo1CCnV96pY4VopG4LtAXBu1bs3qjwiFRMTTgbj0kIDaLd2yooQVoKQN1gWpl0-ykayndsXV1U/s1600/CopyAsHtmlbg.gif); background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; background: #f0f0f0; border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; overflow-wrap: normal; word-wrap: normal;&quot;&gt;package testPackage;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class ClearExample {

	public static void main(String[] args) {
		
		System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;D:\\chromedriver.exe&quot;);
		WebDriver driver=new ChromeDriver();
	    		
	    driver.get(&quot;http://only-testing-blog.blogspot.com/2022/11/relationship.html&quot;);
		
		//Find and locate textbox element by id.
		WebElement gp = driver.findElement(By.id(&quot;gparent_1&quot;));
		
		//Get value of name attribute and print it in console.
		String name_Attr = gp.getAttribute(&quot;name&quot;);
		System.out.println(&quot;Name attribute value = &quot;+name_Attr);
		
		//Get value of type attribute and print it in console.
		String type_Attr = gp.getAttribute(&quot;type&quot;);
		System.out.println(&quot;Type attribute value = &quot;+type_Attr);
		
		//Get value of class attribute and print it in console.
		String class_Attr = gp.getAttribute(&quot;class&quot;);		
		System.out.println(&quot;class attribute value = &quot;+class_Attr);	
	}
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;In above given example, We located element by id. Then get attribute values of name, type, class and then print it in console. It will return values of name and type attributes. Value of class attribute will be null because that attribute is not available on element.&lt;/p&gt;</description><link>http://software-testing-tutorials-automation.blogspot.com/2022/11/selenium-get-attribute-to-get-value-of.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTKGbunhb1vn6AleTTbOlDGmiiL0EqBlg4YMeIq-9D38ae53q7EC1dKnzcoAIeBP0KjiRpg88_wHUg31PsiUpIM-x4unuNkPzJZDyOPsgutRRqQ_sHmxx7duzEVdp2fM76sTwh7u4GXYCp4k52E8mFb-OtZ7TeFG3qCavsnV5F0AQrmy1j8xmXKSukyQ/s72-w400-h208-c/Selenium%20getAttribute()%20method.png" height="72" width="72"/><thr:total>0</thr:total></item></channel></rss>