{"id":93927,"date":"2019-07-10T10:00:47","date_gmt":"2019-07-10T07:00:47","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=93927"},"modified":"2019-07-03T16:54:36","modified_gmt":"2019-07-03T13:54:36","slug":"test-automation-selenium-webdriver","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html","title":{"rendered":"22 Practical Tips To Test Automation With Selenium WebDriver"},"content":{"rendered":"<p>Test automation with Selenium has empowered website testers over the globe to perform automated website testing with ease. Webdriver is a core component of the Selenium framework using which you can perform automated <a href=\"https:\/\/www.lambdatest.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">cross browser testing <\/a>of your website or web application against different types of browsers e.g. Google Chrome, Mozilla Firefox, Safari, Opera, Internet Explorer, Microsoft Edge, etc.<\/p>\n<p>The primary advantage of performing test automation with Selenium Webdriver over other web automation tools\/frameworks is the support for a wide number of programming languages namely Python, Java, C#, Ruby, PHP, JavaScript, .Net, Perl, etc. If you are new to automation testing with Selenium WebDriver, then you can have a look at our <a href=\"https:\/\/www.lambdatest.com\/blog\/selenium-webdriver-tutorial-for-cross-browser-testing\/\" target=\"_blank\" rel=\"noopener noreferrer\">Selenium WebDriver tutorial for automated cross browser testing<\/a> where we talk about the overall architecture of Selenium and how the framework can be used with popular programming languages. You can also check my previous article on <a href=\"https:\/\/www.lambdatest.com\/blog\/selenium-grid-setup-tutorial-for-cross-browser-testing\/\" target=\"_blank\" rel=\"noopener noreferrer\">Selenium Grid setup Tutorial for cross browser testing<\/a>, to leverage the ability of <a href=\"https:\/\/www.lambdatest.com\/blog\/speed-up-automated-parallel-testing-in-selenium-with-testng\/\" target=\"_blank\" rel=\"noopener noreferrer\">parallel testing with Selenium<\/a>. Irrespective of the programming language being used, there are certain best practices that are applicable for performing test automation with Selenium Webdriver (independent of the development language).<\/p>\n<p>In this article, I will share with you some key tips for Selenium automation testing, that touch upon aspects of code optimization, performance improvements, dynamic web-page loading, handling CSS and HTML code, etc.<\/p>\n<p><b>Note<\/b> \u2013 Majority of these coding tips for test automation with Selenium WebDriver are generic in nature and can be applied irrespective of the programming language used for the development of test scripts. However, for below demonstration, we have made use of Selenium with Python language.<\/p>\n<h2 class=\"wp-block-heading\">Selenium Tip #1 \u2013 Setting The Executable Path Of The Selenium Webdriver<\/h2>\n<p>In order to communicate with the browser under test, you need to first download the corresponding plugin\/webdriver from <a href=\"https:\/\/www.seleniumhq.org\/download\/\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">their official website<\/a>. This plugin would be responsible for communicating with the browser and it should be present in your machine (on which you are developing the tests). The plugin\/webdriver path has to be set in the Selenium Webdriver configuration.<\/p>\n<p>Though the plugin\/webdriver can be placed in any location since you can provide the static\/relative path in the Selenium Webdriver configuration, the approach can be error prone and you need to keep track of the file path. A better &amp; more reliable approach is to place the corresponding Selenium Webdriver in the location where the driver executable is present, in which case you need not specify the executable path in the Selenium Webdriver configuration.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"686\" height=\"229\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image1.png\" alt=\"Selenium WebDriver\" class=\"wp-image-93929\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image1.png 686w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image1-300x100.png 300w\" sizes=\"(max-width: 686px) 100vw, 686px\" \/><\/figure>\n<\/div>\n<p>If the <b>geckodriver<\/b> is not present in the Browser location, you need to manually add the path of the same in the source code. We import the <b>selenium.webdriver.firefox.firefox_binary<\/b> module to provide the path to the Firefox executable.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom selenium.webdriver.firefox.firefox_binary import FirefoxBinary\n&nbsp;\nff_binary = FirefoxBinary('path\/to\/gecko driver')\nbrowser = webdriver.Firefox(firefox_binary=ff_binary)\n<\/pre>\n<p>As seen in the code snippet below, we have not specified the location of the geckodriver (Firefox Webdriver) since it is placed in the same location where Firefox browser is present. This is more reliable approach compared to the previous one and can help in reducing basic errors in implementation of test automation with Selenium.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">''' Import the required modules for development '''\nfrom selenium import webdriver\nfrom selenium.webdriver.common.keys import Keys\nfrom time import sleep\n&nbsp;\n'''Creation of Firefox Webdriver '''\ndriver = webdriver.Firefox()\ndriver.get(\"https:\/\/www.lambdatest.com\/\")\n<\/pre>\n<h2 class=\"wp-block-heading\">Selenium Tip #2 \u2013 Capture Screenshot Of Test Automation With Selenium WebDriver<\/h2>\n<p>While performing tests, you would have come across requirements where a screenshot has to be captured for verifying results of the tests. Selenium WebDriver offers three APIs through which you can take a screenshot of a web-page.<\/p>\n<ol class=\"wp-block-list\">\n<li>save_screenshot(\u2018path-where-screenshot-should-be-saved\/filename.png\u2019)<\/li>\n<li>get_screenshot_as_file(\u2018path-where-screenshot-should-be-saved\/filename.png\u2019)<\/li>\n<li>get_screenshot_as_png()<\/li>\n<\/ol>\n<p>The first two APIs lets you save the screen of the current window in a .png file. The API returns False if there is an IOError, else it returns True. These APIs would only work if the file extension is .png, else Python throws an error &amp; the saved content might not be viewable. If you wish to capture a screen of your current window in a binary format then make use of get_screenshot_as_png() API.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">''' Import the required modules for development '''\nfrom selenium import webdriver\nimport StringIO\nfrom PIL import Image\n&nbsp;\n'''Creation of Firefox Webdriver '''\ndriver = webdriver.Firefox()\ndriver.get(\"https:\/\/www.lambdatest.com\/\")\n&nbsp;\n'''Taking screenshot of the web-page. File would be saved in the location where the source code is present '''\n&nbsp;\n'''Option - 1'''\ndriver.save_screenshot('screenshot_1.png');\n&nbsp;\n&nbsp;\n'''Option - 2'''\ndriver.get_screenshot_as_file('screenshot_2.png');\n'''Option - 3'''\nscreenshot = driver.get_screenshot_as_png();\n&nbsp;&nbsp;&nbsp;&nbsp;\nscreenshot_size = (20, 10, 480, 600)\nimage = Image.open (StringIO.StringIO(screen))\nregion = image.crop(screenshot_size)\nregion.save('screenshot_3.jpg', 'JPEG', optimize=True)\n<\/pre>\n<h2 class=\"wp-block-heading\">Selenium Tip #3 \u2013 Refreshing WebPage While Automation Testing With Selenium WebDriver<\/h2>\n<p>There might be scenarios where there is a requirement for refreshing a web page, especially while waiting for a specific condition. There are a number of ways through which a webpage can be refreshed while performing test automation with Selenium Webdriver, the popular one is listed below.<\/p>\n<h3 class=\"wp-block-heading\">1. driver.refresh() method<\/h3>\n<p>As the name signifies, the <b>refresh()<\/b> method is used to refresh the web page. It is asynchronous in nature hence; you should make use of this API in conjunction with <b>document.readyState()<\/b>.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">''' Import the required modules for development '''\nfrom selenium import webdriver\n&nbsp;\n'''Creation of Firefox Webdriver '''\ndriver = webdriver.Firefox()\ndriver.get(\"https:\/\/www.lambdatest.com\/\")\ndriver.refresh()\n<\/pre>\n<h3 class=\"wp-block-heading\">2. ActionChains() method<\/h3>\n<p>ActionChains() are another way to automate low-level interactions for automation testing with Selenium, such as key press, mouse button actions, etc. In order to refresh the webpage, we make use of the \u2018CTRL + F5\u2019 combination.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">import time\nfrom selenium import webdriver\nfrom selenium.webdriver.common.action_chains import ActionChains\nfrom selenium.webdriver.common.keys import Keys\n&nbsp;\n'''Creation of Firefox Webdriver '''\n# driver = webdriver.Chrome()\ndriver = webdriver.Firefox()\ndriver.get(\"https:\/\/www.lambdatest.com\/\")\n&nbsp;\ntime.sleep(5)\n&nbsp;\nprint(\"Before refresh\")\n&nbsp;\nActionChains(driver) \\\n&nbsp;&nbsp;&nbsp;&nbsp;.key_down(Keys.CONTROL) \\\n&nbsp;&nbsp;&nbsp;&nbsp;.send_keys(Keys.F5) \\\n&nbsp;&nbsp;&nbsp;&nbsp;.key_up(Keys.CONTROL) \\\n&nbsp;&nbsp;&nbsp;&nbsp;.perform()\n&nbsp;\nprint(\"After refresh\")\n&nbsp;\nsleep(5)\ndriver.quit()\n<\/pre>\n<h2 class=\"wp-block-heading\">Selenium Tip #4 \u2013 Open A Webpage In A New Tab<\/h2>\n<p>execute_script can be used to synchronously execute JavaScript code in current window\/frame. Argument (a JavaScript) to open the webpage is passed as the argument to execute_script<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom selenium.webdriver.common.keys import Keys\nfrom time import sleep\n&nbsp;\ndriver = webdriver.Firefox()\ndriver.get(\"http:\/\/www.google.com\/\")\n&nbsp;\ndriver.implicitly_wait(10)\n&nbsp;\n#open tab\ndriver.execute_script(\"window.open('https:\/\/www.lambdatest.com', 'new tab')\")\n&nbsp;\nsleep(5)\ndriver.quit()\n<\/pre>\n<h2 class=\"wp-block-heading\">Selenium Tip #5 \u2013 Saving Partial Screenshot Of A Web page<\/h2>\n<p>There are cases where you might need to take a partial screenshot of a webpage as your perform test automation with Selenium. In such cases, you can make use of the Pillow module. You need to first install the Pillow\/PIL module using the command<\/p>\n<p><code>pip install pillow<\/code><\/p>\n<p>Screenshot of the entire webpage is taken using the <b>get_screenshot_as_png()<\/b> API. Once the screenshot is ready, the PIL library is used to open the captured image in memory, after which the image (which contains the entire webpage screenshot) is cropped to get the resultant image.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\n''' Install the Pillow module using the command pip install pillow '''\nfrom PIL import Image\nfrom io import BytesIO\n&nbsp;\ndriver = webdriver.Firefox()\ndriver.get('http:\/\/google.com\/')\n&nbsp;\n# Use the Inspection tool to find the location of the logo\nelement = driver.find_element_by_id('hplogo')\nimage_location = element.location\nsize = element.size\n&nbsp;\npng = driver.get_screenshot_as_png()\n&nbsp;\n''' Since the webpage screenshot is ready, we can exit the browser.'''\ndriver.quit()\n&nbsp;\n''' PIL Library is used to open the image in memory '''\ncrop_image = Image.open(BytesIO(png))\n&nbsp;\n''' Extract the Left, Right, Top, and Bottom co-ordinates ''' \n&nbsp;\nleft = image_location['x']\ntop = image_location['y']\nright = image_location['x'] + size['width']\nbottom = image_location['y'] + size['height']\n&nbsp;\ncrop_image = crop_image.crop((left, top, right, bottom))\ncrop_image.save('logo-screenshot.png')\n<\/pre>\n<h2 class=\"wp-block-heading\">Selenium Tip #6 \u2013 Execute JavaScript Code<\/h2>\n<p>execute_script is used to execute JavaScript code as you perform test automation with Selenium WebDriver. The syntax is <b>driver.execute_script(\u201cjavascript code here\u201d)<\/b>.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image2-1024x441.png\" alt=\"Selenium WebDriver\" class=\"wp-image-93930\" width=\"768\" height=\"331\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image2-1024x441.png 1024w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image2-300x129.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image2-768x331.png 768w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image2.png 1345w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n<p>As shown in the example below, a on_click action of Register is performed [Class name is home-cta].<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom time import sleep\n&nbsp;\ndriver = webdriver.Firefox()\ndriver.get(\"https:\/\/www.lambdatest.com\")\n&nbsp;\ndriver.execute_script(\"document.getElementsByClassName('home-cta')[0].click()\")\n&nbsp;\nsleep(10)\n&nbsp;\ndriver.close()\n<\/pre>\n<h2 class=\"wp-block-heading\">Selenium Tip #7 \u2013 Extracting Results Of JavaScript Code<\/h2>\n<p>After invoking the JavaScript code for automation testing with Selenium, you need to extract the results of these JavaScript codes. You can make use of the return keyword in order to get the result of a JavaScript code as shown in the extended example where we explained JavaScript.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom time import sleep\n&nbsp;\ndriver = webdriver.Firefox()\ndriver.get(\"https:\/\/www.lambdatest.com\")\n&nbsp;\ndriver.execute_script(\"document.getElementsByClassName('home-cta')[0].click()\")\n&nbsp;&nbsp;&nbsp;&nbsp;\nresult = driver.execute_script(\"return 0\")\nprint(result)\n&nbsp;\nsleep(10)\n&nbsp;\ndriver.close()\n<\/pre>\n<h2 class=\"wp-block-heading\">Selenium Tip #8 \u2013 Handling Multiple Browser Types For Automated Cross Browser Testing<\/h2>\n<p>There are multiple scenarios that you might need to test your code against different browsers e.g. Firefox, Chrome, Internet Explorer. The practice of testing a website across different browsers is termed as <a href=\"https:\/\/www.lambdatest.com\/selenium-automation\" target=\"_blank\" rel=\"noopener noreferrer\">automated browser testing<\/a>. To perform automated browser testing with Selenium automation testing, you should incorporate selective handling of those browsers in your unittest code or pytest code. A code snippet (which makes use of pytest) to handle multiple browsers is shown below:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"wp-block-preformatted brush:java\"># Import the 'modules' that are required for execution\n&nbsp;\nimport pytest\nfrom selenium import webdriver\nfrom selenium.webdriver.chrome.options import Options\nfrom selenium.webdriver.common.keys import Keys\nfrom time import sleep\n&nbsp;\n#Fixture for Firefox\n@pytest.fixture(params=[\"chrome\", \"firefox\"],scope=\"class\")\ndef driver_init(request):\n&nbsp;&nbsp;&nbsp;&nbsp;if request.param == \"chrome\":\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Perform necessary actions here\n&nbsp;&nbsp;&nbsp;&nbsp;if request.param == \"firefox\":\n&nbsp;&nbsp;&nbsp;&nbsp;# Perform necessary actions here\n&nbsp;&nbsp;&nbsp;&nbsp;yield\n&nbsp;&nbsp;&nbsp;&nbsp;web_driver.close()\n&nbsp;&nbsp;&nbsp;&nbsp;...........\n&nbsp;&nbsp;&nbsp;&nbsp;...........\n<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/accounts.lambdatest.com\/register\/\"><img decoding=\"async\" width=\"431\" height=\"330\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/cta-img.png\" alt=\"\" class=\"wp-image-93931\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/cta-img.png 431w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/cta-img-300x230.png 300w\" sizes=\"(max-width: 431px) 100vw, 431px\" \/><\/a><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">Selenium Tip #9 \u2013 Locating Elements On A Web Page Using CSS Locators<\/h2>\n<p>As you perform test automation with Selenium, locating web elements on a page comes as a foundation to your automation scripts. In case you want to perform conditional execution based on the presence of a particular kind of web element like Tag, Class, ID, etc. you can make use of find_elements_*** API. Some of them are mentioned below<\/p>\n<ul class=\"wp-block-list\">\n<li>find_elements_by_class_name \u2013 Find elements by Class Name<\/li>\n<li>find_elements \u2013 Find elements by strategy and locator<\/li>\n<li>find_element_by_link_text \u2013 Find element by link text<\/li>\n<li>find_element_by_partial_link_text \u2013 Find element by partial match of link text<\/li>\n<\/ul>\n<p>Shown below is the usage of find_element_by_partial_link_text &amp; find_elements_by_class_name where the elements are searched on <a href=\"https:\/\/www.lambdatest.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/www.lambdatest.com\/<\/a> which is the URL under test.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom selenium.webdriver.chrome.options import Options\nfrom selenium.webdriver.common.keys import Keys\nfrom time import sleep\nfrom selenium.common.exceptions import NoSuchElementException\n&nbsp;\ndriver = webdriver.Firefox()\ndriver.get(\"https:\/\/www.lambdatest.com\")\n&nbsp;\ntry:\n&nbsp;&nbsp;&nbsp;&nbsp;element = driver.find_element_by_partial_link_text(\"START TESTING\")\n&nbsp;&nbsp;&nbsp;&nbsp;print(\"Partial text Element found\")\n&nbsp;&nbsp;&nbsp;&nbsp;element = driver.find_elements_by_class_name('home-btn-2')\n&nbsp;&nbsp;&nbsp;&nbsp;print(\"Button Element found\")\nexcept NoSuchElementException:\n&nbsp;&nbsp;&nbsp;&nbsp;print(\"No element found\")\n&nbsp;&nbsp;&nbsp;&nbsp;\nsleep(10)\ndriver.close()\n<\/pre>\n<p><a href=\"https:\/\/www.lambdatest.com\/blog\/using-link-text-and-partial-link-text-in-selenium\/\" target=\"_blank\" rel=\"noopener noreferrer\">Check Our Blog Series For A Detailed Read About Various CSS Locators Used For Test Automation With Selenium.<\/a><\/p>\n<h2 class=\"wp-block-heading\">Selenium Tip #10 \u2013 HTML Source Of WebElement<\/h2>\n<p>innerHTML property can be used to capture the source code of a WebPage. innerHTML is also used to examine any changes in the page since the page was first loaded by the web browser. You can write the entire source code in a .html file for future reference.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom selenium.webdriver.chrome.options import Options\nfrom selenium.webdriver.common.keys import Keys\nfrom time import sleep\nimport io\n&nbsp;\ndriver = webdriver.Firefox()\ndriver.get(\"https:\/\/www.lambdatest.com\")\n&nbsp;\nelem = driver.find_element_by_xpath(\"\/\/*\")\nsource_code = elem.get_attribute(\"innerHTML\")\n&nbsp;\nfilename = open('lambdatest_page_source.html', 'w')\nfilename.write(source_code)\nfilename.close()\n&nbsp;&nbsp;&nbsp;&nbsp;\nsleep(10)\n&nbsp;\ndriver.close()\n<\/pre>\n<h2 class=\"wp-block-heading\">Selenium Tip #11 \u2013 Perform Mouse Over Actions<\/h2>\n<p>There would be scenarios where you might need to perform a click on an item which is a part of the menu or an item which is a part of a multi-level menu. First we locate the Menu item and then perform a click operation on the intended menu item.<\/p>\n<p>In the example below, the URL under test is <a href=\"https:\/\/www.lambdatest.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/www.lambdatest.com\/<\/a>. The intent is to navigate to the <a href=\"https:\/\/www.lambdatest.com\/selenium-automation\" target=\"_blank\" rel=\"noopener noreferrer\">Automation Tab<\/a> on the home page. The first task is to locate the Menu which matches the ID <b>bs-example-navbar-collapse-1<\/b>. By using the Inspect Tool, we get the correct element-id, details is as shown in the snapshot<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image5-1024x480.png\" alt=\"Selenium WebDriver\" class=\"wp-image-93932\" width=\"768\" height=\"360\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image5-1024x480.png 1024w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image5-300x141.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image5-768x360.png 768w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image5.png 1345w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n<p>We move to the Menu using the move_to_element operation which is a part of the action_chains module. Next task is to locate the Menu item which contains the text <b>\u2018Automation\u2019<\/b> for which we make use of <b>find_element_by_xpath(\u201c\/\/a[contains(text(),\u2019Automation\u2019)]\u201d)<\/b> after which Click operation is performed.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom selenium.webdriver.common.action_chains import ActionChains\nfrom time import sleep\n&nbsp;&nbsp;&nbsp;&nbsp;\ndriver = webdriver.Firefox()\ndriver.get(\"https:\/\/www.lambdatest.com\")\n&nbsp;\naction = ActionChains(driver);\n&nbsp;\n# Head on the top-level menu on Lambdatest website\nparent_level_menu = driver.find_element_by_id(\"bs-example-navbar-collapse-1\")\naction.move_to_element(parent_level_menu).perform()\n&nbsp;\n# Perform a click operation on the Menu item which contains text Automation\nchild_level_menu = driver.find_element_by_xpath(\"\/\/a[contains(text(),'Automation')]\")\nchild_level_menu.click();\n&nbsp;\nsleep(10)\n&nbsp;\ndriver.close()\n<\/pre>\n<h2 class=\"wp-block-heading\">Selenium Tip #12 \u2013 Closing Tabs Without Closing The Browser<\/h2>\n<p>One of the most basic yet mandatory tips for any test automation Selenium script is to realize how to close tabs without closing the entire browser. <b>driver.close()<\/b> closes the focused tab and <b>driver.quit()<\/b> will close all the tabs (of the browser) along with quitting of the driver. In case you need to keep the browser window open (and quitting all other tabs), you can make use of <b>switch_to.window<\/b> method which has the input parameter as window <b>handle-id<\/b>.<\/p>\n<p><b>Note<\/b> \u2013 There are other methods to approach this problem. <b>window.open<\/b> method can be used with appropriate options (i.e. opening new window, opening new tab, etc.). Sending the right key combinations using <b>send_keys<\/b> can be used, but the behavior has dependency on version of geckodriver (for Firefox), version of chromedriver, etc. Hence, <b>send_keys approach is not preferable since the output can vary based on WebDriver versions.<\/b><\/p>\n<p>In the below example, we open one new window which contains the test URL and close other windows. We only make use of window_handles to achieve the requirement.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nimport time\n \ndriver = webdriver.Firefox()\ndriver.get('https:\/\/www.google.com')\n# Open a new window\ndriver.execute_script(\"window.open('');\")\ntime.sleep(5)\n# Switch to the new window since the focus would still be on the old window\ndriver.switch_to.window(driver.window_handles[1])\ndriver.get(\"https:\/\/lambdatest.com\")\ntime.sleep(5)\n# close the active tab\ndriver.close()\ntime.sleep(5)\n# Switch back to the first tab\ndriver.switch_to.window(driver.window_handles[0])\ndriver.get(\"https:\/\/www.yahoo.com\")\ntime.sleep(5)\n# Close the only tab, will also close the browser.\n#driver.close()\n<\/pre>\n<h2 class=\"wp-block-heading\">Selenium Tip #13 \u2013 Handling Drop-Down Menu In A Page<\/h2>\n<p>There is a requirement where you have to select a particular option from a drop-down menu present in a web-page. There are a number of ways in which you can select the desired option from the drop-down menu.<\/p>\n<ul class=\"wp-block-list\">\n<li>select_by_index(desired_index_value)<\/li>\n<li>select_by_visible_text(\u201ctext_to_be_selected_from_drop_down_menu\u201d)<\/li>\n<li>select_by_value(value)<\/li>\n<\/ul>\n<p>We will use <a href=\"http:\/\/demos.dojotoolkit.org\/dijit\/tests\/test_Menu.html\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">http:\/\/demos.dojotoolkit.org\/dijit\/tests\/test_Menu.html<\/a> for Selenium automation testing on this requirement. Before we select the required element from the drop-down menu, it is important to get the ID of the element under test. We use find_element_by_xpath method to locate the element and once we have located the element (using the ID), we select the value from the drop-down menu.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image7-1024x532.png\" alt=\"Selenium WebDriver\" class=\"wp-image-93933\" width=\"768\" height=\"399\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image7-1024x532.png 1024w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image7-300x156.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image7-768x399.png 768w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image7.png 1348w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n<p>In the example below, we have shown the different methods through which you can select an element from the menu (<b>@aria-label=\u2019select\u2019<\/b>)<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom selenium.webdriver.support.ui import Select\nfrom time import sleep\nfrom selenium.common.exceptions import NoSuchElementException\nfrom pip._vendor.distlib import resources\n&nbsp;\ndriver = webdriver.Firefox()\ndriver.get(\"http:\/\/demos.dojotoolkit.org\/dijit\/tests\/test_Menu.html\")\n&nbsp;\n''' Let the page load completely '''\nsleep(5)\n&nbsp;\ntry:\n&nbsp;&nbsp;&nbsp;&nbsp;''' You can derive these details by using Web Inspector '''\n&nbsp;&nbsp;&nbsp;&nbsp;select_element = Select(driver.find_element_by_xpath(\"\/\/select[@aria-label='select']\"))\n&nbsp;&nbsp;&nbsp;&nbsp;# Option 1 - Selecting the drop-down item by using the text\n&nbsp;&nbsp;&nbsp;&nbsp;select_element.select_by_visible_text(\"bleed through\")\n&nbsp;&nbsp;&nbsp;&nbsp;sleep(5)\n&nbsp;&nbsp;&nbsp;&nbsp;# Option 2 - Selecting the drop-down item by using the index value\n&nbsp;&nbsp;&nbsp;&nbsp;select_element.select_by_index(0)\n&nbsp;&nbsp;&nbsp;&nbsp;sleep(5)\n&nbsp;&nbsp;&nbsp;&nbsp;# Option 3 - Selection of desired option using value\n&nbsp;&nbsp;&nbsp;&nbsp;''' This option would fail since there is no value in the page\n&nbsp;&nbsp;&nbsp;&nbsp; which we are testing right now ''' \n&nbsp;&nbsp;&nbsp;&nbsp;# select_element.select_by_value('2')\nexcept NoSuchElementException:\n&nbsp;&nbsp;&nbsp;&nbsp;print(\"Element not found\")\n&nbsp;\n''' Addition of delay so that we can have a look at the output '''\nsleep(5)\n&nbsp;\n''' Release the resources '''\ndriver.quit()\n<\/pre>\n<h2 class=\"wp-block-heading\">Selenium Tip #14 \u2013 Handling Operations With Check Boxes<\/h2>\n<p>Check boxes are common elements in web pages which are used in scenarios where you have to select only one option from a number of options. Like drop-down menu handling, we locate the required checkbox using <b>find_element_by_xpath<\/b> method and once we find the checkbox, a click operation is performed.<\/p>\n<p>We will use <a href=\"http:\/\/demos.dojotoolkit.org\/dijit\/tests\/form\/test_CheckBox.html\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">http:\/\/demos.dojotoolkit.org\/dijit\/tests\/form\/test_CheckBox.html<\/a> for Selenium automation testing and the requirement is to \u2018check\u2019 the checkbox which has the value cb7: normal checkbox. The matching is done using driver.find_elements_by_xpath(\u201c\/\/*[contains(text(), \u2018text to be searched\u2019)]\u201d).<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom selenium.webdriver.support.ui import Select\nfrom time import sleep\nfrom selenium.common.exceptions import NoSuchElementException\nfrom pip._vendor.distlib import resources\n&nbsp;\ndriver = webdriver.Firefox()\ndriver.get(\"http:\/\/demos.dojotoolkit.org\/dijit\/tests\/form\/test_CheckBox.html\")\n&nbsp;\n''' Let the page load completely '''\nsleep(20)\n&nbsp;\ntry:\n&nbsp;&nbsp;&nbsp;&nbsp;''' You can derive these details by using Web Inspector '''\n&nbsp;&nbsp;&nbsp;&nbsp;driver.find_element_by_xpath(\"\/\/*[contains(text(), 'cb7: normal checkbox')]\").click()\nexcept NoSuchElementException:\n&nbsp;&nbsp;&nbsp;&nbsp;print(\"Element not found\")\n&nbsp;\n''' Addition of delay so that we can have a look at the output '''\nsleep(5)\n&nbsp;\n''' Release the resources '''\ndriver.quit()\n<\/pre>\n<h2 class=\"wp-block-heading\">Selenium Tip #15 \u2013 Selecting Element via CSS Selector<\/h2>\n<p>There is a provision to locate elements on a webpage using the CSS locator as you perform test automation with Selenium. <b>find_elements_by_css_selector<\/b> can be used for locating elements where details of element (label, link, ID, etc.) to be located have to passed as the input argument. It finds a list of elements within this element\u2019s children by CSS Selector.<\/p>\n<p>The intent is to locate the Login button on <a href=\"https:\/\/lambdatest.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/lambdatest.com\/<\/a> using find_elements_by_css_selector and perform click operation. The code associated with Login is below. Code inspection tool snapshot also gives the required information.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">&lt;html&gt;\n........\n&lt;li class=\"login\"&gt;\n&lt;a href=\"https:\/\/accounts.lambdatest.com\/register\"&gt;Free Sign Up&lt;\/a&gt;\n&lt;\/li&gt;\n.....\n&lt;\/html&gt;\n<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image8-1024x544.png\" alt=\"Selenium WebDriver\" class=\"wp-image-93934\" width=\"768\" height=\"408\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image8-1024x544.png 1024w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image8-300x160.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image8-768x408.png 768w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image8-620x330.png 620w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image8.png 1364w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n<p>Hence, we pass li.login as an argument to find_element_by_css_selector and once it locates the element, Click operation is performed.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom selenium.webdriver.support.ui import Select\nfrom time import sleep\nfrom selenium.common.exceptions import NoSuchElementException\nfrom pip._vendor.distlib import resources\n&nbsp;\ndriver = webdriver.Firefox()\ndriver.get(\"https:\/\/www.lambdatest.com\/\")\n&nbsp;\n''' Let the page load completely '''\nsleep(20)\n&nbsp;\ntry:\n&nbsp;&nbsp;&nbsp;&nbsp;''' You can derive these details by using Web Inspector '''\n&nbsp;&nbsp;&nbsp;&nbsp;driver.find_element_by_css_selector(\"li.login\").click()\nexcept NoSuchElementException:\n&nbsp;&nbsp;&nbsp;&nbsp;print(\"Element not found\")\n&nbsp;\n''' Addition of delay so that we can have a look at the output '''\nsleep(5)\n&nbsp;\n''' Release the resources '''\ndriver.quit()\n<\/pre>\n<p><a href=\"https:\/\/www.lambdatest.com\/blog\/how-pro-testers-use-css-selectors-in-selenium-automation-scripts\/\" target=\"_blank\" rel=\"noopener noreferrer\">Don\u2019t Forget To Read Our Comprehensive Article On Using CSS Selectors For Test Automation With Selenium. <\/a><\/p>\n<h2 class=\"wp-block-heading\">Selenium Tip #16 \u2013 Explicit Wait For Handling Different Scenarios<\/h2>\n<p>It is very normal to observe a scenario in Selenium automation testing where a webpage may take time to load or you want a particular web element on the page to be visible before triggering your test code. In such cases, you need to perform <b>Explicit Wait<\/b> which is a piece of code through which define a condition to occur before you proceed further in the code.<\/p>\n<p>Selenium has <b>WebDriverWait<\/b> which can be applied on any web element with a condition &amp; time duration. It can throw an exception in case the element on which the wait is performed is not present or a timeout occurs.<\/p>\n<p>In the example below, we wait for link_text \u2018Sitemap\u2019 to load on the page and the timeout is specified in the <b>WebDriverWait<\/b> method. If the element is not loaded within the timeout duration, we throw an exception.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom selenium.common.exceptions import TimeoutException\nfrom selenium.common.exceptions import NoSuchElementException\nfrom selenium.webdriver.common.by import By\nfrom pip._vendor.distlib import resources\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.support import expected_conditions as EC\n&nbsp;\ndriver = webdriver.Firefox()\ndriver.get(\"https:\/\/www.lambdatest.com\/\")\ntimeout = 10\n&nbsp;\ntry:\n&nbsp;&nbsp;&nbsp;&nbsp;''' We wait till the time link with text SITEMAP is loaded '''\n&nbsp;&nbsp;&nbsp;&nbsp;''' If that link text is not present on the page, it gives a time out '''\n&nbsp;&nbsp;&nbsp;&nbsp;''' Try replacing Sitemap with Sitemap123 and you can encounter a timeout '''\n&nbsp;&nbsp;&nbsp;&nbsp;element_present = EC.presence_of_element_located((By.LINK_TEXT, 'Sitemap'))\n&nbsp;&nbsp;&nbsp;&nbsp;WebDriverWait(driver, timeout).until(element_present)\nexcept TimeoutException:\n&nbsp;&nbsp;&nbsp;&nbsp;print(\"Timed out while waiting for page to load\")\ndriver.quit()\n<\/pre>\n<pre class=\"wp-block-preformatted brush:java\">Selenium Tip #17 \u2013 Scroll Operations In A Web Page\n<\/pre>\n<p>You may have a requirement where you need to perform scroll-up\/scroll-down operation on a page while performing test automation with Selenium. You can achieve the same using execute_script with window.scrollTo JS code as the argument. In the example below, we scroll to the end of the page after the website under test is loaded.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom time import sleep\n&nbsp;\ndriver = webdriver.Firefox()\ndriver.get(\"https:\/\/www.lambdatest.com\/\")\ntimeout = 10\n&nbsp;\n''' Scroll to the end of the page '''\ndriver.execute_script(\"window.scrollTo(0, document.body.scrollHeight);\")\n&nbsp;\n''' Sleep is added so that you can have a look at the output '''\nsleep(10)\n&nbsp;\n''' Scroll again to the top of the page '''\ndriver.execute_script(\"window.scroll(0, 0);\")\n&nbsp;\nsleep(10)\ndriver.quit()\n<\/pre>\n<h2 class=\"wp-block-heading\">Selenium Tip #18 \u2013 Zoom In &amp; Zoom out using Selenium<\/h2>\n<p>In order to zoom in or zoom out while Selenium automation testing, you should use the <b>transform CSS property<\/b> (for the corresponding browser) that lets you perform zoom in, zoom out, rotate, skew, etc. operations on the page.<\/p>\n<p>The CSS parameters for different types of browsers are below<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"630\" height=\"216\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/Untitled.png\" alt=\"Selenium WebDriver\" class=\"wp-image-93935\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/Untitled.png 630w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/Untitled-300x103.png 300w\" sizes=\"(max-width: 630px) 100vw, 630px\" \/><\/figure>\n<\/div>\n<p>In the example below, we zoom-out the web page that is loaded in the browser by 200% and later zoom in by 100% (i.e. back to normal). Since we are using the Firefox browser, we have made use of MozTransform CSS property.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom time import sleep\n&nbsp;\ndriver = webdriver.Firefox()\ndriver.get(\"https:\/\/www.lambdatest.com\/\")\ntimeout = 10\n&nbsp;\n''' Zoom in by 200% '''\ndriver.execute_script('document.body.style.MozTransform = \"scale(2.0)\";')\ndriver.execute_script('document.body.style.MozTransformOrigin = \"0 0\";')\n&nbsp;\nsleep(10)\n&nbsp;\n''' Zoom out by 100% '''\n&nbsp;\ndriver.execute_script('document.body.style.MozTransform = \"scale(1.0)\";')\ndriver.execute_script('document.body.style.MozTransformOrigin = \"0 0\";')\n&nbsp;\n''' Sleep is added so that you can have a look at the output '''\nsleep(10)\n&nbsp;\n''' Release all the resources '''\ndriver.quit()\n<\/pre>\n<h2 class=\"wp-block-heading\">Selenium Tip #19 \u2013 Find Size Of An Element In A Web Page<\/h2>\n<p>You have to first search for the element by ID and then use the .size property to calculate the size of the searched element. In the example below, we calculate the size of the button create_programmatic_menu (ID = createDestoryButton) in the page <a rel=\"noopener nofollow noreferrer\" href=\"http:\/\/demos.dojotoolkit.org\/dijit\/tests\/test_Menu.html\" target=\"_blank\">http:\/\/demos.dojotoolkit.org\/dijit\/tests\/test_Menu.html<\/a><\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image9-1024x491.png\" alt=\"Selenium WebDriver\" class=\"wp-image-93936\" width=\"768\" height=\"368\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image9-1024x491.png 1024w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image9-300x144.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image9-768x368.png 768w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image9.png 1364w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom time import sleep\n&nbsp;\ndriver = webdriver.Firefox()\ndriver.get(\"http:\/\/demos.dojotoolkit.org\/dijit\/tests\/test_Menu.html\")\ntimeout = 10\n&nbsp;\nsearch_element = driver.find_element_by_id(\"createDestroyButton\")\n&nbsp;\nprint(search_element.size)\n&nbsp;\n''' Release all the resources '''\ndriver.quit()\n<\/pre>\n<p>When you execute the above code, it would output the size of the button (ID \u2013 CreateDestroyButton).<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"504\" height=\"136\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image3.png\" alt=\"Selenium WebDriver\" class=\"wp-image-93937\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image3.png 504w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image3-300x81.png 300w\" sizes=\"(max-width: 504px) 100vw, 504px\" \/><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">Selenium Tip #20 \u2013 Get X &amp; Y coordinates Of An Element In A Web Page<\/h2>\n<p>You have to follow a similar approach which you used for calculating the size of an element. You have to first search for the element by ID and then use the <b>.location property<\/b> to calculate the X &amp; Y coordinates of the searched element.<\/p>\n<p>The test URL is <a href=\"http:\/\/demos.dojotoolkit.org\/dijit\/tests\/test_Menu.html\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">http:\/\/demos.dojotoolkit.org\/dijit\/tests\/test_Menu.html<\/a> and we calculate the X &amp; Y co-ordinates of the button create_programmatic_menu (ID = createDestoryButton)<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom time import sleep\n&nbsp;\ndriver = webdriver.Firefox()\ndriver.get(\"http:\/\/demos.dojotoolkit.org\/dijit\/tests\/test_Menu.html\")\ntimeout = 10\n&nbsp;\nsearch_element = driver.find_element_by_id(\"createDestroyButton\")\n&nbsp;\nprint(search_element.location)\n&nbsp;\n''' Release all the resources '''\ndriver.quit()\n<\/pre>\n<p>When you execute the above code, it would output the X, Y coordinates e of the button (ID \u2013 CreateDestroyButton).<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"540\" height=\"149\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image4.png\" alt=\"Selenium WebDriver\" class=\"wp-image-93938\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image4.png 540w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image4-300x83.png 300w\" sizes=\"(max-width: 540px) 100vw, 540px\" \/><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">Selenium Tip #21 \u2013 Disable JavaScript Using Custom Profile<\/h2>\n<p>In case you want to disable JavaScript support of the browser to validate automated cross browser compatibility with Selenium automation testing, you need to change the profile settings of the browser under test (in our case, it is Firefox) and apply the changes to the profile. We make use of DEFAULT_PREFERENCES[\u2018frozen\u2019][\u2018javascript.enabled\u2019] = False to disable the JavaScript support for the browser.<\/p>\n<p>Once the code is executed, you should verify the profile changes by typing about:config in the address bar and searching for the value of javascript.enabled property.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\n&nbsp;\n''' Since we have the geckodriver &amp; Firefox browser in same location '''\n''' We do not pass the location of the Firefox profile '''\nff_profile = webdriver.FirefoxProfile()\n&nbsp;\nff_profile.DEFAULT_PREFERENCES['frozen']['javascript.enabled'] = False\nff_profile.set_preference(\"app.update.auto\", False)\nff_profile.set_preference(\"app.update.enabled\", False)\n&nbsp;\n''' Update the preferences '''\nff_profile.update_preferences()\n&nbsp;\n''' Load the Firefox browser with the updated profile '''\ndriver = webdriver.Firefox(ff_profile)\n&nbsp;\n''' Verify whether the changes are working fine or not '''\ndriver.get(\"about:config\")\n<\/pre>\n<p>Below is the screenshot of about:config settings (after the code execution) in Firefox<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image6-1024x161.png\" alt=\"Selenium WebDriver\" class=\"wp-image-93939\" width=\"768\" height=\"121\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image6-1024x161.png 1024w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image6-300x47.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image6-768x121.png 768w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/image6.png 1343w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">Selenium Tip #22 \u2013 Setting Manual Proxy Settings<\/h2>\n<p>In some scenarios, you may want to change the Proxy Settings in order to execute your tests. For changing the proxy settings, you need to first import the module <b>selenium.webdriver.common.proxy<\/b>. You have to set the proxy type to <b>MANUAL<\/b>, after which you change the proxy settings and apply to the new settings to the browser under test (in our case it is Firefox).<\/p>\n<p>You need to replace ip_address &amp; port_number with the IP address &amp; port number that you plan to use for your testing.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">from selenium import webdriver\nfrom selenium.webdriver.common.proxy import Proxy, ProxyType\n&nbsp;\nproxy_settings = Proxy()\n&nbsp;\n''' The proxy settings are first changed to Manual '''\nproxy_settings.proxy_type = ProxyType.MANUAL\n&nbsp;\n''' Replace ip_address with Proxy IP address and '''\n''' port_number with the port number which you plan to use '''\nproxy_settings.http_proxy = \"ip_address:port_number\"\nproxy_settings.socks_proxy = \"ip_address:port_number\"\nproxy_settings.ssl_proxy = \"ip_address:port_number\"\n&nbsp;\n''' You can add capabilties for different browsers &amp; devices '''\ncapabilities = webdriver.DesiredCapabilities.FIREFOX\nproxy_settings.add_to_capabilities(capabilities)\n&nbsp;\ndriver = webdriver.Firefox(desired_capabilities=capabilities)\n<\/pre>\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n<p>We have covered the majority of the Selenium tips to help you perform test automation with Selenium like a professional. Though you can verify your website\/web-app on different browsers, devices, and operating systems using your local machine, the extent of testing will be limited since you cannot cover the complete spectrum of devices + operating systems + browsers (&amp; browser versions). This is where you should make use of these tips &amp; tricks to perform automated cross browser testing for your website\/web application.<\/p>\n<p>You have to make minimal changes in order to move your local Selenium automation test code to LambdaTest<a href=\"https:\/\/www.lambdatest.com\/selenium-automation\" target=\"_blank\" rel=\"noopener noreferrer\"> on-cloud Selenium Grid<\/a> as you begin to expand your test coverage by testing your web-app on more than 2000 real browsers + OS + devices combinations. You also get integrations to numerous CI CD tools, project management tools and more.<\/p>\n<p>Test automation with Selenium can be a tough task but with the actionable insights, rather practical tips for Selenium automation testing that I listed above in this article. You can be proficient with test automation in Selenium. Let me know if there are any other tips for test automation with Selenium that have helped you fast track your test cycles. Cheers &amp; happy testing! <\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>Published on Java Code Geeks with permission by Himanshu Seth, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener noreferrer\">JCG program<\/a>. See the original article here: <a href=\"https:\/\/www.lambdatest.com\/blog\/tips-for-test-automation-with-selenium\/\" target=\"_blank\" rel=\"noopener noreferrer\">22 Practical Tips To Test Automation With Selenium WebDriver<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Test automation with Selenium has empowered website testers over the globe to perform automated website testing with ease. Webdriver is a core component of the Selenium framework using which you can perform automated cross browser testing of your website or web application against different types of browsers e.g. Google Chrome, Mozilla Firefox, Safari, Opera, Internet &hellip;<\/p>\n","protected":false},"author":81931,"featured_media":93767,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[287,1805,273],"class_list":["post-93927","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-selenium","tag-test-automation","tag-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>22 Practical Tips To Test Automation With Selenium WebDriver - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn about Selenium WebDriver? Check our article presenting 22 tips to test automation with selenium webdriver.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"22 Practical Tips To Test Automation With Selenium WebDriver - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about Selenium WebDriver? Check our article presenting 22 tips to test automation with selenium webdriver.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-10T07:00:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/selenium-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Himanshu Sheth\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Himanshu Sheth\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"26 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/07\\\/test-automation-selenium-webdriver.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/07\\\/test-automation-selenium-webdriver.html\"},\"author\":{\"name\":\"Himanshu Sheth\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/a25d993a76017c1c681bf9ca6e6ad8ad\"},\"headline\":\"22 Practical Tips To Test Automation With Selenium WebDriver\",\"datePublished\":\"2019-07-10T07:00:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/07\\\/test-automation-selenium-webdriver.html\"},\"wordCount\":3051,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/07\\\/test-automation-selenium-webdriver.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/selenium-logo.jpg\",\"keywords\":[\"Selenium\",\"Test Automation\",\"Testing\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/07\\\/test-automation-selenium-webdriver.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/07\\\/test-automation-selenium-webdriver.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/07\\\/test-automation-selenium-webdriver.html\",\"name\":\"22 Practical Tips To Test Automation With Selenium WebDriver - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/07\\\/test-automation-selenium-webdriver.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/07\\\/test-automation-selenium-webdriver.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/selenium-logo.jpg\",\"datePublished\":\"2019-07-10T07:00:47+00:00\",\"description\":\"Interested to learn about Selenium WebDriver? Check our article presenting 22 tips to test automation with selenium webdriver.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/07\\\/test-automation-selenium-webdriver.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/07\\\/test-automation-selenium-webdriver.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/07\\\/test-automation-selenium-webdriver.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/selenium-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/selenium-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/07\\\/test-automation-selenium-webdriver.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"22 Practical Tips To Test Automation With Selenium WebDriver\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/a25d993a76017c1c681bf9ca6e6ad8ad\",\"name\":\"Himanshu Sheth\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8a190453d43aa252452a7c12c73f8d396bbe3c7428c79482d046eb611ad1929f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8a190453d43aa252452a7c12c73f8d396bbe3c7428c79482d046eb611ad1929f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8a190453d43aa252452a7c12c73f8d396bbe3c7428c79482d046eb611ad1929f?s=96&d=mm&r=g\",\"caption\":\"Himanshu Sheth\"},\"description\":\"Himanshu Seth is an engineer with 15+ years of experience. He has worked with multi-national companies as well as startups. He is also an avid blogger on technology.\",\"sameAs\":[\"https:\\\/\\\/www.lambdatest.com\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/himanshu-sheth\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"22 Practical Tips To Test Automation With Selenium WebDriver - Java Code Geeks","description":"Interested to learn about Selenium WebDriver? Check our article presenting 22 tips to test automation with selenium webdriver.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html","og_locale":"en_US","og_type":"article","og_title":"22 Practical Tips To Test Automation With Selenium WebDriver - Java Code Geeks","og_description":"Interested to learn about Selenium WebDriver? Check our article presenting 22 tips to test automation with selenium webdriver.","og_url":"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2019-07-10T07:00:47+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/selenium-logo.jpg","type":"image\/jpeg"}],"author":"Himanshu Sheth","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Himanshu Sheth","Est. reading time":"26 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html"},"author":{"name":"Himanshu Sheth","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/a25d993a76017c1c681bf9ca6e6ad8ad"},"headline":"22 Practical Tips To Test Automation With Selenium WebDriver","datePublished":"2019-07-10T07:00:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html"},"wordCount":3051,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/selenium-logo.jpg","keywords":["Selenium","Test Automation","Testing"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html","url":"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html","name":"22 Practical Tips To Test Automation With Selenium WebDriver - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/selenium-logo.jpg","datePublished":"2019-07-10T07:00:47+00:00","description":"Interested to learn about Selenium WebDriver? Check our article presenting 22 tips to test automation with selenium webdriver.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/selenium-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/selenium-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2019\/07\/test-automation-selenium-webdriver.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"22 Practical Tips To Test Automation With Selenium WebDriver"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/a25d993a76017c1c681bf9ca6e6ad8ad","name":"Himanshu Sheth","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/8a190453d43aa252452a7c12c73f8d396bbe3c7428c79482d046eb611ad1929f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/8a190453d43aa252452a7c12c73f8d396bbe3c7428c79482d046eb611ad1929f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8a190453d43aa252452a7c12c73f8d396bbe3c7428c79482d046eb611ad1929f?s=96&d=mm&r=g","caption":"Himanshu Sheth"},"description":"Himanshu Seth is an engineer with 15+ years of experience. He has worked with multi-national companies as well as startups. He is also an avid blogger on technology.","sameAs":["https:\/\/www.lambdatest.com"],"url":"https:\/\/www.javacodegeeks.com\/author\/himanshu-sheth"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/93927","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/81931"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=93927"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/93927\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/93767"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=93927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=93927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=93927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}