<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Samapti Ganguly on Medium]]></title>
        <description><![CDATA[Stories by Samapti Ganguly on Medium]]></description>
        <link>https://medium.com/@gangulysamapti11?source=rss-5084f87cc473------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*h4onX-s1QH0WawLJ9-PzvQ.jpeg</url>
            <title>Stories by Samapti Ganguly on Medium</title>
            <link>https://medium.com/@gangulysamapti11?source=rss-5084f87cc473------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 21:30:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gangulysamapti11/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Web Scraping Using Selenium Java and JSoup]]></title>
            <link>https://medium.com/@gangulysamapti11/web-scraping-using-selenium-java-and-jsoup-4274f92afa8f?source=rss-5084f87cc473------2</link>
            <guid isPermaLink="false">https://medium.com/p/4274f92afa8f</guid>
            <dc:creator><![CDATA[Samapti Ganguly]]></dc:creator>
            <pubDate>Sat, 17 Jun 2023 03:01:44 GMT</pubDate>
            <atom:updated>2023-06-17T03:01:44.203Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>What is web scraping?</em></strong></p><p>In simple word, Web scraping refers to the automated process of extracting data from websites. It involves using specialized tools or software to retrieve required information from web pages and store it in a structured format for further analysis or use. Web scraping enables users to gather large amounts of data quickly and efficiently, making it a valuable technique for various applications.</p><p><strong><em>Why do we need to scrape data from website or benefit of web scraping?</em></strong></p><p>i) <em>Data Extraction</em>: Very specific data elements can be extracted from any website through web scraping, such as product details, prices, social media posts, reviews and many more. These data can be used for research, analysis or creating databases.<br>ii) <em>Lead Generation</em>: Web scraping can be used to extract contact information, such as email addresses or phone numbers, from websites. This information is valuable for lead generation.<br>iii) <em>Market Research</em>: Businesses can gain insights into market dynamics, identify opportunities, and make informed decisions by analyzing the information gathered by web scraping on competitors, pricing trends, customer reviews and product features.<br>iv) <em>Automation and Efficiency</em>: Web scraping eliminates the need for manual data collection, saves time and effort by automating the process of data extraction</p><p>There are many more advantages of web scraping, but it is not possible to mention them all here, so am moving forward to the steps.</p><p><strong><em>Steps:</em></strong> <br>1. <em>Set up the development environment</em>: Install Java, Selenium and Jsoup on your machine. Gradle or Maven can be used as build automation tool to manage dependencies. Update POM adding this following dependencies: —</p><pre> &lt;dependency&gt;<br>      &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;<br>      &lt;artifactId&gt;selenium-chrome-driver&lt;/artifactId&gt;<br>      &lt;version&gt;3.14.0&lt;/version&gt;<br>    &lt;/dependency&gt;<br>&lt;!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin --&gt;<br>    &lt;dependency&gt;<br>      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br>      &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;<br>      &lt;version&gt;3.0.0&lt;/version&gt;<br>    &lt;/dependency&gt;<br>&lt;!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --&gt;<br>    &lt;dependency&gt;<br>      &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;<br>      &lt;artifactId&gt;selenium-java&lt;/artifactId&gt;<br>      &lt;version&gt;4.8.1&lt;/version&gt;<br>    &lt;/dependency&gt;<br>&lt;!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager --&gt;<br>    &lt;dependency&gt;<br>      &lt;groupId&gt;io.github.bonigarcia&lt;/groupId&gt;<br>      &lt;artifactId&gt;webdrivermanager&lt;/artifactId&gt;<br>      &lt;version&gt;5.3.2&lt;/version&gt;<br>    &lt;/dependency&gt;<br>    &lt;dependency&gt;<br>      &lt;groupId&gt;org.jsoup&lt;/groupId&gt;<br>      &lt;artifactId&gt;jsoup&lt;/artifactId&gt;<br>      &lt;version&gt;1.15.4&lt;/version&gt;<br>    &lt;/dependency&gt;<br>&lt;!-- https://mvnrepository.com/artifact/org.apache.poi/poi --&gt;<br>    &lt;dependency&gt;<br>      &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;<br>      &lt;artifactId&gt;poi&lt;/artifactId&gt;<br>      &lt;version&gt;5.2.2&lt;/version&gt;<br>    &lt;/dependency&gt;<br>&lt;!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl --&gt;<br>    &lt;dependency&gt;<br>      &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;<br>      &lt;artifactId&gt;log4j-slf4j-impl&lt;/artifactId&gt;<br>      &lt;version&gt;2.17.1&lt;/version&gt;<br>      &lt;scope&gt;test&lt;/scope&gt;<br>    &lt;/dependency&gt;<br>    &lt;dependency&gt;<br>      &lt;groupId&gt;junit&lt;/groupId&gt;<br>      &lt;artifactId&gt;junit&lt;/artifactId&gt;<br>      &lt;version&gt;3.8.1&lt;/version&gt;<br>      &lt;scope&gt;test&lt;/scope&gt;<br>    &lt;/dependency&gt;<br>  &lt;/dependencies&gt;</pre><p>2. <em>Initialize a Selenium WebDriver</em>: Create an instance of the WebDriver (e.g., ChromeDriver, FirefoxDriver) to automate the web browser. Make sure you have the appropriate WebDriver executable for the browser you’re using. Here I have used WebDriverManager.<br>3. <em>Navigate to the recipe website</em>: Use the WebDriver to navigate to the recipe website’s URL.</p><pre>public class Scraper {<br><br> private WebDriver driver;<br><br> public Scraper() throws Exception {<br>//WebDriverManager.firefoxdriver().setup();<br>  //driver = new FirefoxDriver();<br><br>  WebDriverManager.chromedriver().setup();<br>  driver = new ChromeDriver();<br><br>  driver.navigate().to(&quot;https://www.tarladalal.com/&quot;);</pre><p>4. <em>Locate the recipe elements</em>: Inspect the HTML structure of the recipe website to identify the elements that contain the recipe information you want to scrape. Use the WebDriver’s methods to locate these elements, such as findElement() or findElements(), and store them in variables.<br>Example as follows : — —</p><pre>public void parseDataOnPage() throws IOException {<br><br>  // list of WebElements that store all the links<br>  List&lt;WebElement&gt; raw_recipes = driver.findElements(By.className(&quot;rcc_recipename&quot;));<br><br>  // arraylist to store all the links in string form (can be optimized)<br>  ArrayList&lt;String&gt; links = new ArrayList&lt;&gt;(14);<br><br>  // loop through raw_recipes to fill the links arraylist<br>  for (WebElement e : raw_recipes)<br>  {<br>   // .findElement -----&gt; finds the tag &lt;a&gt; inside the current WebElement<br>   // .getAttribute ----&gt; returns the href attribute of the &lt;a&gt; tag in the current WebElement<br>   links.add(e.findElement(By.tagName(&quot;a&quot;)).getAttribute(&quot;href&quot;));<br>  }<br><br>  List&lt;WebElement&gt; raw_ids = driver.findElements((By.className(&quot;rcc_rcpno&quot;)));</pre><p>5.<em> Extract the recipe data using Jsoup</em>: For easier parsing and extraction convert the WebDriver’s page source to a jsoup document object. To extract specific data from the HTML elements you identified earlier, use Jsoup’s selectors and methods. For an example, you can use select() to find the specific elements based on CSS selectors.<br>6. <em>Process the extracted data</em>: Iterate over the extracted elements and extract the desired information, such as recipe titles, ingredients, method, preparation time, cooking time. I have extracted data for Diabetes.<br>Example as follows: —</p><pre><br>   // get the specific area that deals with the ingredients<br>   Element ingredients_div = r_page.select(&quot;div#rcpinglist&quot;).first();<br>   // get the list of ingredients which are blue (links), made an executive decision to screw the rest of them &gt;:(<br>   assert ingredients_div != null;<br>   Elements ingredients_links = ingredients_div.select(&quot;a&quot;);<br><br>   // loop to add the ingredients received into the arraylist in string format<br>   for (Element e : ingredients_links) {<br>    ingredients.add(e.text());<br>   }<br>   if (containsFlagIngredient(ingredients)) continue;<br><br>   // get the name of the current recipe<br>   String name = Objects.requireNonNull(r_page.getElementById(&quot;ctl00_cntrightpanel_lblRecipeName&quot;)).text();<br><br>   // .parseInt ----------&gt; converts a String to int<br>   // .select ------------&gt; focuses on a specific tag that you identified and everything inside it<br>   // .first -------------&gt; get only one of the tag instead of all of them<br>   // .text --------------&gt; returns the text in the selected tag in String format<br>   // .replaceAll --------&gt; replaces all substrings that match the first param to the second param in the string<br>   // .strip -------------&gt; removes spaces (whitespaces) from the front and end of the string<br>   int prepTime;<br>   int cookTime;<br>   try {<br>    prepTime = Integer.parseInt(r_page.select(&quot;[itemprop=prepTime]&quot;).first().text().replaceAll(&quot;[^\\d]&quot;, &quot;&quot;).strip());<br>    cookTime = Integer.parseInt(r_page.select(&quot;[itemprop=cookTime]&quot;).first().text().replaceAll(&quot;[^\\d]&quot;, &quot;&quot;).strip());<br>   } catch (Exception e) {<br>    prepTime = 0;<br>    cookTime = 0;<br>   }</pre><p>7. <em>Handle pagination and navigation</em>: If the website has multiple pages or sections, you may need to implement logic to handle pagination or navigate through different sections of the website. Use the WebDriver to click on next page buttons or follow links to load additional content.<br>Example as follows: — —</p><pre>// scrapes and parses all recipes in the entire site, 23 pages for diabetic recipes<br> public void parseDataFull(int pageNum) throws IOException {<br><br>  pageNum = Math.min(pageNum, 23);<br>  for (int i = 1; i &lt;= pageNum; i++) {<br>   driver.navigate().to(&quot;https://www.tarladalal.com/recipes-for-indian-diabetic-recipes-370?pageindex=&quot; + i);<br>   parseDataOnPage();<br>   System.out.println(&quot;Finished Page &quot; + i);<br>  }<br> }</pre><p>8.Store the data in a suitable data structure or perform any necessary data manipulation. Here I have stored data in an excel sheet.</p><p><em>Here are the steps to store Excel data using Java: — <br>1. Add Apache POI dependency: Add Apache POI library to your POM.<br>2.Import required classes: Import the necessary classes from the Apache POI library, such as Workbook, Sheet, Row, and Cell.<br>3.Create a workbook: Create a new instance of the Workbook class (e.g., XSSFWorkbook for .xlsx files) to represent the Excel workbook.<br>4.Create a sheet: Create a new sheet within the workbook using the </em><em>createSheet() method.<br>5.Prepare the data: Prepare the data that you want to store in the Excel file. This can be done by storing the data in a suitable data structure.<br>6.Iterate over the data: Iterate over the data structure and create rows and cells in the sheet using the </em><em>createRow() and </em><em>createCell() methods. Set the cell values using the appropriate data type and the </em><em>setCellValue() method.<br>7.Write the workbook to a file: Use a </em><em>FileOutputStream to write the workbook to a file. Specify the file name and path where you want to store the Excel file.<br>8.Handle exceptions: Handle any exceptions that may occur during file operations, such as IOException, by using try-catch blocks or propagating the exception to the caller.<br>9.Close the workbook: After writing the data to the Excel file, close the workbook using the </em><em>close() method to release system resources.</em></p><p><em>These steps outline the general process of storing Excel data using Java. By following these steps and using the Apache POI library, you can create and populate Excel files programmatically from your Java code.</em></p><figure><img alt="E.g. Image of my excel sheet" src="https://cdn-images-1.medium.com/max/1024/1*bYoFOx7uMvx9Vpyw05TDww.png" /><figcaption>E.g. Image of my Excel Sheet</figcaption></figure><p>9. Clean up and repeat (if needed): Once you finish scraping the desired data, close the WebDriver and clean up any resources.</p><pre>public void closeDriver()<br> {<br>  driver.close();<br> }</pre><p><strong><em>Disclaime</em></strong><em>r</em>:<br><em>Remember to check the website’s terms of service or any legal restrictions before scraping any data. Also, be respectful of the website’s resources and avoid causing excessive load or disrupting their services.</em></p><p><em>Please note that web scraping may be subject to legal restrictions or terms of service of the website you are scraping. Make sure you comply with all applicable laws and respect the website’s policies.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4274f92afa8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cross Browser Testing using TestNG]]></title>
            <link>https://medium.com/@gangulysamapti11/cross-browser-testing-using-testng-15b6588db561?source=rss-5084f87cc473------2</link>
            <guid isPermaLink="false">https://medium.com/p/15b6588db561</guid>
            <dc:creator><![CDATA[Samapti Ganguly]]></dc:creator>
            <pubDate>Sun, 27 Nov 2022 21:09:27 GMT</pubDate>
            <atom:updated>2022-11-29T14:35:56.352Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*X_V_7pZYDFJg5WovsiXKUw.png" /></figure><p>Once upon a time, when there was Internet Explorer, who ruled the world. With time the glory has gone. Today there are Microsoft Edge, Google Chrome, Mozilla Firefox, and Apple Safari, all are in a race to capture the world. Nowadays, nobody knows which browser user loves the most to open the website. Users have multiple options to choose any browser to open the website, a developer cannot assume all the users are on Chrome driver. Since development of such type of website become so important, so is the testing. While testing the website efficiently, and to take the control over the browser driver, we need Selenium. Now we need TestNG to use Selenium more efficiently.</p><h3>What is cross browser testing?</h3><p>The process of testing the functionalities of the website in multiple browser and operating system (OS) is called Cross browser testing. A type of functional testing to check whether the website or application is working fine with different browser and OS. It is possible to perform cross browser testing either manually or in an automated way, but manual testing is tedious.</p><p>We perform the automated cross-browser testing with the help of Selenium and TestNG. It’s necessary to understand why we perform cross-browser testing.</p><h3>Why do we need to perform a Cross-Browser Testing?</h3><p>Web-based applications are totally different from windows applications. A web application can be opened in any browser. We all know that end user can choose any browser to open the application, since it cannot be developed considering one browser only. If we do, it might render perfectly on that particular browser but after publishing what will happen in other browser? Suppose if we incorporated some tags those were supported by only its latest version? We have not yet considered the resolutions and operating systems. Browser manufacturers always tends to do something new with their browser to cope up with the competition including the engine where the browser is built. Since the engine is different, the way how a browser understands the web languages (CSS, JavaScript and HTML) is also different. If the position property of CSS works fine on Chrome, it will not work on Safari. Reason behind is the absence of -WebKit tag. Cross browser testing using TestNG ensures a much better performance on different browsers and operating systems.</p><p><strong><em>Reasons to do a cross browser testing and some possible issues as follows:</em></strong></p><ol><li>Image orientation</li><li>Mismatch of font size in different browser</li><li>Page alignment and div size</li><li>Browser incompatibility with OS</li><li>JavaScript implementation can be different</li><li>Validation difference of CSS,HTML also possible</li><li>Some browser still not supporting HTML5</li><li>Unsupported tags can be revealed and taken care of by turnaround codes</li></ol><h3>How To Perform Cross-Browser Testing In TestNG Using Selenium</h3><p>Selenium Webdriver gives the opportunity to automate test cases using Chrome, Firefox, Internet Explorer and Safari browser.</p><p>TestNG Annotation required to access the parameter values from xml to the Java program is @Parameters. TestNG Parameters help us to avoid writing the same repetitive code again and again. Using TestNG Parameter annotation, we can cut down on lines of code significantly and makes efficient use of TestNG annotation. That is what a tester aims for when working on TestNG.</p><p><em>The below code will demonstrate how to perform cross-browser testing in TestNG using selenium webdriver:-</em></p><pre>package MultiBrowser;<br><br>import org.openqa.selenium.WebDriver;<br>import org.openqa.selenium.chrome.ChromeDriver;<br>import org.openqa.selenium.firefox.FirefoxDriver;<br>import org.testng.Assert;<br>import org.testng.annotations.AfterTest;<br>import org.testng.annotations.BeforeTest;<br>import org.testng.annotations.Parameters;<br>import org.testng.annotations.Test;<br><br><br>import io.github.bonigarcia.wdm.WebDriverManager;<br><br>public class Crossbrowsertest {<br><br> WebDriver driver;<br> <br> @Parameters({&quot;url&quot;, &quot;browserType&quot;})<br> @BeforeTest<br> public void invokeBrowser(String url, String browserType)<br> {<br>  if(browserType.equals(&quot;Chrome&quot;))<br>  {<br>   <br>   WebDriverManager.chromedriver().setup();<br>   driver = new ChromeDriver();<br>  }<br>  <br>  else <br>  {<br>   <br>   WebDriverManager.firefoxdriver().setup();<br>   driver = new FirefoxDriver();<br>  }<br>  <br>  driver.get(url);<br>  <br> }<br> @Test<br> public void validateTitle()<br> {<br>  String expected = &quot;Google&quot;;<br>  String actual = driver.getTitle();<br>  Assert.assertEquals(actual, expected);<br> }<br> @AfterTest<br> public void closeBrowser() {<br>  driver.close();<br> }<br> <br>}</pre><p><em>Creating the xml file following the below steps as shown in the image</em>:-</p><ol><li>Right click on the program</li><li>Hover on TestNG</li><li>Select Convert to TestNG</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*mTOrkLwVSAd1M_EhuKoYcg.png" /></figure><p><em>testng.xml:</em></p><p>Since we are using TestNG Parameter, we need to specify the values from the TestNG XML file that will pass to the test case file.</p><p>Here the testng.xml has two test tags, this test case will execute two times for two different browsers.</p><p>First test ‘ChromeBrowser’ will pass the value of parameter ‘browserType’ as ‘Chrome’ so ChromeDriver will be executed. This test case will run on Chrome Browser.</p><p>Second test ‘FirefoxBrowser’ will pass the value of parameter ‘browserType’ as ‘Firefox’ so FirefoxDriver will be executed. This test case will run on Firefox Browser.</p><p>As follows:-</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;!DOCTYPE suite SYSTEM &quot;https://testng.org/testng-1.0.dtd&quot;&gt;<br>&lt;suite name=&quot;Suite&quot; verbose = &quot;5&quot;&gt; <br>  &lt;test  name=&quot;ChromeBrowser&quot;&gt;<br>  &lt;parameter name=&quot;url&quot; value=&quot;https://www.google.com&quot;/&gt;<br>  &lt;parameter name=&quot;browserType&quot; value=&quot;Chrome&quot;/&gt;<br>    &lt;classes&gt;<br>      &lt;class name=&quot;MultiBrowser.Crossbrowsertest&quot;/&gt;<br>    &lt;/classes&gt;<br>  &lt;/test&gt; &lt;!-- Test --&gt;<br><br> &lt;test  name=&quot;FirefoxBrowser&quot;&gt;<br>  &lt;parameter name=&quot;url&quot; value=&quot;https://www.google.com&quot;/&gt;<br>  &lt;parameter name=&quot;browserType&quot; value=&quot;Firefox&quot;/&gt;<br>    &lt;classes&gt;<br>      &lt;class name=&quot;MultiBrowser.Crossbrowsertest&quot;/&gt;<br>    &lt;/classes&gt;<br>  &lt;/test&gt; &lt;!-- Test --&gt;<br>&lt;/suite&gt; &lt;!-- Suite --&gt;</pre><p>To execute the test in TestNG follow the below steps:-</p><ol><li>Right click on the testng.xml file</li><li>Hover on Run as</li><li>Click TestNG suite</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*fWUosWaGneeAdHAr5xCZuw.png" /><figcaption>Executing the test case in tesng</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*ojwx1W4fRW3xDn9XOD4GpQ.png" /><figcaption>Console</figcaption></figure><p>As we can see both of the test cases passed successfully running the website on different browsers.</p><h3>Take away from this blog in short</h3><ol><li>Cross browser testing is an essential part of developing a website.</li><li>Cross browser testing is a technique to check the performance of websites on different web browsers.</li><li>The mobile revolution has changed the way how websites are viewed today. There are billions of mobile users in the world, cannot be ignored.</li><li>At present, website can be open on any device, any version, any browser, any OS or any resolution. Keeping this in mind the developers and testers need to be prepared for this before any catastrophe happens.</li><li>Selenium can support different types of browsers for automation and can be integrated with TestNG to perform Multi Browser Testing to ensure certain things.</li><li>From parameter in testng.xml we can pass browser name, can create WebDriver reference accordingly in a test case also.</li></ol><p>Happy testing.</p><p>Thank You!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15b6588db561" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WebDriverManager in Selenium]]></title>
            <link>https://medium.com/@gangulysamapti11/webdrivermanager-in-selenium-fb4570ed68bd?source=rss-5084f87cc473------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb4570ed68bd</guid>
            <dc:creator><![CDATA[Samapti Ganguly]]></dc:creator>
            <pubDate>Tue, 09 Aug 2022 02:41:17 GMT</pubDate>
            <atom:updated>2022-11-28T03:11:32.763Z</atom:updated>
            <content:encoded><![CDATA[<p>WebDriverManager!!</p><p>A true friend to automation, right?</p><p>I will tell you why I said so. What is WebDriverManager and what does it do? Let’s jump right into it!</p><p>WebDriverManager is an API that grants users the freedom of handling the driver executable like chromedriver, geckodriver etc in a fully automated manner.</p><h4>Life before WebDriverManager</h4><p>Before starting to automate the web application we need to download the driver executable manually for the required browsers like chrome, firefox, etc.</p><p>Then, after downloading the executable into our local system, we need to set the path.</p><p>It is important to verify the version of the browser all the time and keep updating, else it will not work.</p><p>In addition to all these points, each different operating system, be it Windows, MacOS, Linux, BSD etc. has a unique or separate method to obtain those drivers, which makes it quite a hassle to manage over hybrid systems.</p><p><em>This is the traditional method for setting up browser path bellow</em>:</p><pre>//For Chrome Browser<br>System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;./Drivers/chromedriver.exe&quot;);<br><br>//For Firefox Browser<br>System.setProperty(&quot;webdriver.gecko.driver&quot;, &quot;./Drivers/geckodriver.exe&quot;);</pre><h4>Tedious? Lots of manual stuff? NO WORRIES!</h4><p>WebDriverManager makes it easy and convert the manual stuff into automation.</p><p>It verifies the version of the browser(eg chrome, firefox, Edge etc.)<br> installed in your local machine by its own.</p><p>It also uses the latest version of the driver(chromedriver, geckodriver etc.) regardless which version of driver installed in your machine.</p><h4><strong>Instantiate a browser using WebDriverManager in Selenium Java:</strong></h4><p>Add this dependency to pom.xml in your project. Don&#39;t forget to save it.</p><pre>&lt;!-- <a href="https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager">https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager</a> --&gt;<br>&lt;dependency&gt;<br>    &lt;groupId&gt;io.github.bonigarcia&lt;/groupId&gt;<br>    &lt;artifactId&gt;webdrivermanager&lt;/artifactId&gt;<br>    &lt;version&gt;5.2.3&lt;/version&gt;<br>&lt;/dependency&gt;</pre><p>This is the time to get rid of all the above manual stuff. You can replace the code form “ system.setProperty()” call to WebDriverManager.Xdriver().setup();</p><p>It resolves compatibility issues of the driver binaries for all the browsers.</p><p>Several drivers managers for different browsers are provided by WebDriverManager. As follows :</p><pre>WebDriverManager.chromedriver().setup();<br>WebDriverManager.firefoxdriver().setup();<br>WebDriverManager.edgedriver().setup();<br>WebDriverManager.operadriver().setup();<br>WebDriverManager.chromiumdriver().setup();<br></pre><p><em>Sample selenium project with browser setup</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*NDWNPhbb3AXH7Hg0LTysWg.jpeg" /></figure><h4>Instantiate a browser using WebDriver-Manager in Selenium Python:</h4><p>WebDriver-Manager is a free opensource library which can smartly handle all the hazardous methods of using traditional way in Python as well.</p><p><strong><em>Prerequisites</em></strong>: Make sure Selenium is installed.( Else,run in command <br>-pip install selenium)</p><p>Next step -install webdriver-manager by running the following command</p><pre>pip install webdriver-manager<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*pA73FXefYQ42-PU2mdJ6MA.png" /><figcaption>Installing webdriver_manager</figcaption></figure><p>It is advisable to verify whether selenium and webdriver-manager are installed by running the following command</p><p>pip list</p><p>For Chrome Browser, use :</p><pre>from selenium import webdriver<br><strong>from webdriver_manager.chrome import ChromeDriverManager<br></strong><br><strong>driver = webdriver.Chrome(ChromeDriverManager().install())</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3W5vYBtLOyrV_tqCdnSMTA.png" /></figure><p>For Firefox Browser, use :</p><pre>from selenium import webdriver<br>from webdriver_manager.firefox import GeckoDriverManager</pre><pre>driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())</pre><p><strong>Summery</strong></p><p>WebDriverManager is a true friend to automation. It saves time, eliminates a lot of tedious manual work, helps in resolving incompatibility issues to make Selenium Automation easier and interesting. Happy testing.</p><p>Thank You!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb4570ed68bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[XPath]]></title>
            <link>https://medium.com/@gangulysamapti11/xpath-9e21efbd02d1?source=rss-5084f87cc473------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e21efbd02d1</guid>
            <category><![CDATA[selenium-test-automation]]></category>
            <category><![CDATA[xpath]]></category>
            <dc:creator><![CDATA[Samapti Ganguly]]></dc:creator>
            <pubDate>Thu, 07 Jul 2022 15:35:31 GMT</pubDate>
            <atom:updated>2022-12-21T00:47:41.816Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SfhVdVXWmuyG5tq1hqJ3gQ.png" /></figure><h4>Introduction</h4><p>The XPath is a navigation tool for XML documents that is used to traverse and locate elements in an XML file. However, XPath is not an exclusive tool for XML files/documents only, it can be used to travel through any hierarchical markup file/document (XML, HTML, etc).</p><h4>Types of XPath</h4><p>There are multiple ways to express an XPath. The major types of XPath are separate according to the way they refer to the elements (nodes) in the document. The two major types of XPath are:</p><ul><li>Absolute XPath — The path starts from the root node of the document (the body element by default in a typical HTML file).</li></ul><p>Example: /html/body/div[1]/header/div[1]/div/div/div/div/div/div/div/div[1]/div/div/a/img</p><ul><li>Relative XPath — The path starts from any specified node of the user (the root node is defined by the user, primarily done by specifying the element type after the // symbol).</li></ul><p>Example: //*[<a href="http://twitter.com/id">@id</a>=”main-header”]/div/div/div/div/div[1]/div/div/a/img</p><h4>Basic structure of XPath</h4><p>There are seven types of nodes used in XPath. They are as follows: element, attribute, text, namespace, processing-instruction, comment and document nodes. XML documents are known as trees of nodes. The topmost element of the tree is called the root element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IOajLLC581ugR3FMaA-fpw.png" /><figcaption><strong>Typical structure of XPath</strong></figcaption></figure><p>//tagName[@attribute=&#39;Value&#39;]/...</p><ul><li>// refers to the current element (for absolute XPath, it’s normally the default root node of the document, and any recognizable element for relative XPath)</li><li>tagName is the name of the specified root node. This can be user-specified (relative XPath) or it can be either body or head (for HTML and XML docs — Absolute XPath).</li><li>[] is used to move down hierarchically from the root into the document (if possible).</li><li>@ specifies that an attribute will be used to identify the desired element.</li><li>attribute refers to a known and accessible attribute of the element in question.</li><li>Value is a string literal that is used as a validation string so that the XPath selects the correct element.</li></ul><blockquote>Note: There are many cases where the XPath is unable to access the specified element due to many reasons ranging from inaccessibility to aliens invading the DOM structure of the page. A general rule of thumb is to add more information about the path taken from the root to get there to make it more specific. The simplest way to make the path more detailed is by adding a / to the current path and then defining the next step the path should take in order to find the element.</blockquote><h4>XPath in Selenium</h4><p>The XPath system in Selenium is used to get the location of nodes pointing to the elements such that the located elements can be used for means of automation. In essence, one can use XPath to access the element in a specific webpage and then use Selenium’s tools to manipulate those elements.</p><h4>Customized XPath in Selenium</h4><p>Not all XPaths created will or should match every specific use-case for it. So, in many cases, there are paths which are arguably better and serve the requirement better than the auto generated or the complete one.</p><figure><img alt="Example of a customized XPath (//h1[@id=’firstHeading’]). The path points to the header title of the Wikipedia Page of XPath." src="https://cdn-images-1.medium.com/max/871/1*N_hKTOpxoUw26kFm8IK5Cg.jpeg" /><figcaption><strong>Example of a customized XPath</strong></figcaption></figure><p>There are a myriad of customization options that XPath offers to aid in automation. Some of the more useful and effective ones are as follows:</p><ul><li>xpath = &quot;//li[<a href="http://twitter.com/id">@id</a>=’ca-view’]&quot;</li><li>xpath = &quot;//a[text()=&#39;Feature&#39;]&quot;</li><li>xpath = &quot;//label[<a href="http://twitter.com/class">@class</a>=’selected mw-list-item collapsible’]&quot;</li><li>//ul[contains(text(), &#39;Sign in&#39;]</li><li>//input[@name=&#39;site-header&#39;]</li><li>//a[input(text(),&#39;Login&#39;)]</li><li>//button[@type=&#39;button&#39; and @class=&#39;btn&#39;]</li><li>//a[@title=&#39;Get-in-touch&#39; or @id=&#39;menu-item-95&#39;]</li><li>//div[@class=&#39;dropdown&#39;]//button[@type=&#39;btn&#39; and @class=&#39;button btn-secondary dropdown-toggle&#39; and @id=dropdownMenuButton&#39;]</li></ul><p>Summary</p><p>XPath is a very powerful and vast topic. I tried to condense the major and important parts into a more readable format through this blog post. While very powerful, the XPath is not a monolithic concept. There exists multiple options for customization and configuration ranging from locating the element or node by utilizing the ID, Name or CSS locator attributes. They are said to be the most popular and fast locators. However, it is not possible to locate the element by id, name or css selectors all the time. In such cases XPath in selenium plays a vital role to locate the actual and dynamic element.</p><p>Happy Testing !!</p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e21efbd02d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>