{"id":48009,"date":"2025-06-23T18:07:44","date_gmt":"2025-06-23T12:37:44","guid":{"rendered":"https:\/\/www.foundit.sg\/career-advice\/?p=48009"},"modified":"2025-06-25T11:25:03","modified_gmt":"2025-06-25T05:55:03","slug":"python-selenium-interview-questions-and-answers","status":"publish","type":"post","link":"https:\/\/www.foundit.sg\/career-advice\/python-selenium-interview-questions-and-answers\/","title":{"rendered":"Python Selenium Interview Questions with Answers: Top 50"},"content":{"rendered":"\n<p><!-- wp:paragraph -->\r\n<p>Selenium with Python has become one of the most sought-after skills in test automation roles today. From fintech startups to established MNCs like Grab, DBS Bank, and Shopee in Singapore, companies are hiring QA and SDET professionals proficient in Python Selenium automation. Whether you're preparing for your first job or targeting advanced Selenium Python interview roles, this guide compiles the <strong>Top Python Selenium Interview Questions and Answers<\/strong>, designed to help you tackle real-world scenarios, automation frameworks, and coding logic confidently.<\/p>\r\n<!-- \/wp:paragraph -->\r\n\r\n<!-- wp:paragraph -->\r\n<p>Each question is accompanied by a <strong>theoretical explanation<\/strong> followed by a <strong>Python code snippet, <\/strong>ensuring you\u2019re not just memorising answers but understanding the automation context behind them. These include <strong>python selenium interview questions for freshers<\/strong>, <strong>selenium python questions for experienced<\/strong>, and even <strong>tricky selenium with python questions<\/strong> often asked in senior roles. <\/p>\r\n<!-- \/wp:paragraph -->  <\/p>\n\n\n\n<p><\/p>\n\n\n\n\n<div class=\"wp-block-group has-background\" style=\"background-color:#ABB7C245;padding-top:5px;padding-bottom:5px;padding-left:10px;padding-right:10px\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n  <details>\n    <summary><strong>\ud83d\udd3d Table of Contents<\/strong><\/summary>\n    <ol>\n      <li><a href=\"#q1\"><strong>Top Python Selenium Interview Questions<\/strong><\/a><\/li>\n      <li><a href=\"#q11\"><strong>Intermediate Python Selenium Questions<\/strong><\/a><\/li>\n      <li><a href=\"#q21\"><strong>Scenario-Based Questions<\/strong><\/a><\/li>\n      <li><a href=\"#q31\"><strong>Framework and Automation Design<\/strong><\/a><\/li>\n      <li><a href=\"#q41\"><strong>Tricky Python Selenium Questions<\/strong><\/a><\/li>\n      <li><a href=\"#faqs\"><strong>FAQs<\/strong><\/a><\/li>\n    <\/ol>\n  <\/details>\n<\/div><\/div>\n\n\n\n\n\n<div style=\"height: 15px;\"><\/div>\n\n<div style=\"text-align: center;\">\n<a style=\"display: inline-block;background-color: #7900c6;color: #fff;text-align: center;padding: 10px 20px;text-decoration: none;font-size: 18px;border-radius: 4px;font-weight: bold;\" href=\"https:\/\/www.foundit.sg\/search\/python-selenium-jobs-in-bengaluru-bangalore\/utm_source=organic&#038;utm_medium=career-advice&#038;utm_campaign=python-selenium-interview-questions\" target=\"_blank\">Apply for Python Selenium Jobs<\/a>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading has-background\" id=\"q1\" style=\"background-color:#b4e2ff\">Top Python Selenium Interview Questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. What is Selenium, and why is Python preferred with it?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<p><strong>Sample Answer:<\/strong> Selenium is an open-source automation testing tool for web applications across different browsers and platforms. Python is preferred with Selenium due to its simple syntax, large community, and powerful libraries. Python makes it easier to write clear and concise test scripts. It also integrates well with frameworks like PyTest and tools like Allure and Jenkins for reporting and CI\/CD.<\/p>\n<pre><code>from selenium import webdriver\r\ndriver = webdriver.Chrome()\r\ndriver.get(\"https:\/\/example.com\")<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\">2. How do you locate elements in Selenium using Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<p>Selenium provides several methods to locate web elements: by ID, name, class, tag name, XPath, CSS selector, and link text. Among these, XPath and CSS selectors are the most flexible. Choosing the right locator strategy ensures test stability and maintainability.<\/p>\n<pre><code>driver.find_element(By.ID, \"username\")\r\ndriver.find_element(By.XPATH, \"\/\/input[@type='text']\")<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\">3. What is the role of WebDriver in Selenium?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<p>The WebDriver API is the core interface to interact with browsers. Each browser (Chrome, Firefox, Safari, etc.) has a corresponding driver like ChromeDriver or GeckoDriver. WebDriver launches browsers, executes actions (click, type, scroll), and fetches responses. It mimics real user behavior at the DOM level.<\/p>\n<pre><code>driver = webdriver.Firefox()\r\ndriver.get(\"https:\/\/testsite.com\")<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\">4. How do you handle dropdowns using Selenium in Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<p>To work with dropdowns, Selenium uses the <code>Select<\/code> class from <code>selenium.webdriver.support.ui<\/code>. You can select by index, visible text, or value.<\/p>\n<pre><code>from selenium.webdriver.support.ui import Select\r\ndropdown = Select(driver.find_element(By.ID, \"country\"))\r\ndropdown.select_by_visible_text(\"India\")<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\">5. What are different types of waits in Selenium?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<p>Waits help sync test execution with real-time browser actions. Selenium offers three types:<\/p>\n<ul>\n<li><strong>Implicit Wait:<\/strong> Applies globally, waits for a fixed time for elements to appear.<\/li>\n<li><strong>Explicit Wait:<\/strong> Waits for a specific condition like visibility or clickability.<\/li>\n<li><strong>Fluent Wait:<\/strong> Advanced form of explicit wait with polling intervals and exception handling.<\/li>\n<\/ul>\n<pre><code>WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, \"login\")))<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\">6. How do you handle alerts in Selenium?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<p>Alerts are pop-up dialog boxes. Selenium can switch to an alert and perform actions like accept, dismiss, or retrieve text.<\/p>\n<pre><code>alert = driver.switch_to.alert\r\nprint(alert.text)\r\nalert.accept()<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\">7. What is the use of ActionChains in Selenium?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<p>ActionChains are used to perform advanced interactions such as mouse hover, right-click, drag and drop, and double-click. These are useful when normal element methods aren\u2019t enough for dynamic UI events.<\/p>\n<pre><code>from selenium.webdriver.common.action_chains import ActionChains\r\naction = ActionChains(driver)\r\naction.move_to_element(menu).click().perform()<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\">8. How do you take a screenshot in Selenium with Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<p>You can capture a screenshot of the browser window using the <code>save_screenshot()<\/code> method. It\u2019s helpful for debugging failed test cases or logging steps.<\/p>\n<pre><code>driver.save_screenshot(\"homepage.png\")<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\">9. How do you scroll down a webpage in Selenium?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<p>Use JavaScript execution to scroll vertically or horizontally. This is especially useful for lazy-loaded content or infinite scroll pages.<\/p>\n<pre><code>driver.execute_script(\"window.scrollTo(0, document.body.scrollHeight);\")<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\">10. How do you close the browser window in Selenium?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<p>Selenium provides two methods:<\/p>\n<ul>\n<li><code>driver.close()<\/code>: Closes the current browser tab.<\/li>\n<li><code>driver.quit()<\/code>: Closes all tabs and ends the WebDriver session.<\/li>\n<\/ul>\n<pre><code>driver.quit()<\/code><\/pre>\n<\/div>\n\n\n<p class=\"has-background\" style=\"background-color:#ffdeed\"><strong>Read Also: <a href=\"https:\/\/www.foundit.sg\/career-advice\/selenium-interview-questions-and-answers\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Most-Asked Selenium Interview Questions and Answers<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading has-background\" id=\"q11\" style=\"background-color:#b4e2ff\">Intermediate Python Selenium Questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"q11\">11. How do you handle dropdowns using Selenium in Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nIn Selenium Python, handling dropdowns is streamlined with the `Select` class from `selenium.webdriver.support.ui`. Dropdowns built with the HTML `<select>` tag are compatible with this method. You can select options using visible text, index, or value. This is a common requirement in form testing scenarios, such as choosing a country, date, or product option. Always verify if the element is indeed a `<select>` element before applying `Select`.<\/p>\n<pre><code>from selenium.webdriver.support.ui import Select\r\n\r\nselect_element = driver.find_element(By.ID, \"country\")\r\ndropdown = Select(select_element)\r\ndropdown.select_by_visible_text(\"Singapore\")\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q12\">12. How do you wait for an element to be visible or clickable in Python Selenium?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nWaiting is essential in Selenium to avoid flaky tests. Python Selenium provides `WebDriverWait` with `expected_conditions` for explicit waits. Instead of using hard-coded sleeps, which slow down execution, it&#8217;s better to use waits that respond dynamically when the condition is true\u2014like when an element becomes visible or clickable.<\/p>\n<pre><code>from selenium.webdriver.support.ui import WebDriverWait\r\nfrom selenium.webdriver.support import expected_conditions as EC\r\nfrom selenium.webdriver.common.by import By\r\n\r\nwait = WebDriverWait(driver, 10)\r\nelement = wait.until(EC.element_to_be_clickable((By.ID, \"submit\")))\r\nelement.click()\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q13\">13. How can you perform mouse hover actions in Selenium with Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nMouse interactions like hover are managed using the `ActionChains` class. This is useful for triggering hidden dropdowns or tooltips. You first locate the element and then perform a hover action. Selenium simulates real user interaction with the browser, so the hover must be precise to avoid element misalignment issues.<\/p>\n<pre><code>from selenium.webdriver.common.action_chains import ActionChains\r\n\r\nmenu = driver.find_element(By.ID, \"menu\")\r\nActionChains(driver).move_to_element(menu).perform()\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q14\">14. How do you take a screenshot using Selenium Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nCapturing screenshots is a useful debugging technique. In Selenium Python, the `save_screenshot()` or `get_screenshot_as_file()` methods help you capture the current state of the browser. This is particularly useful when tests fail, allowing QA teams to analyse the UI at that moment.<\/p>\n<pre><code>driver.save_screenshot(\"homepage.png\")\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q15\">15. How do you verify the presence of a web element?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nTo check whether a web element exists, you can use `find_elements()` instead of `find_element()`. The former returns an empty list if no element is found\u2014this helps you avoid exceptions and write cleaner logic to verify presence.<\/p>\n<pre><code>elements = driver.find_elements(By.ID, \"logo\")\r\nif elements:\r\n    print(\"Element is present\")\r\nelse:\r\n    print(\"Element not found\")\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q16\">16. How do you handle alerts and popups in Selenium with Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nJavaScript alerts are handled using `switch_to.alert`. This allows you to accept, dismiss, or get the text from alerts. It\u2019s crucial to use waits before accessing alerts, especially if they are triggered by asynchronous actions.<\/p>\n<pre><code>alert = driver.switch_to.alert\r\nprint(alert.text)\r\nalert.accept()\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q17\">17. How do you count the number of links on a webpage using Selenium Python?<\/h3>\n\n\n<div style=\"background-color: #c4c6c845; padding: 12px; border-radius: 6px;\"><strong>Sample Answer:<\/strong><br \/>To count links, locate all `<a>` tags using `find_elements`. This is useful for accessibility and SEO-related test cases, where link counts and href validation are necessary.<\/a>\n<pre><code>links = driver.find_elements(By.TAG_NAME, \"a\")\nprint(\"Total links:\", len(links))\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q18\">18. What is the difference between find_element and find_elements in Selenium Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\n`find_element` returns a single web element and throws an exception if it\u2019s not found. `find_elements` returns a list and doesn\u2019t raise an exception\u2014it just returns an empty list if no elements match. Always use `find_elements` when you expect zero or more elements, like validating lists, tables, or optional UI sections.\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q19\">19. How do you handle iframes in Python Selenium?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nTo interact with elements inside an iframe, you must switch the driver context to the frame first. You can do this using name, ID, index, or WebElement. Always remember to switch back to the default content after the interaction is done.<\/p>\n<pre><code>driver.switch_to.frame(\"iframe_id\")\r\n# perform actions\r\ndriver.switch_to.default_content()\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q20\">20. How do you scroll down a page using Selenium with Python?<\/h3>\n\n\n<div style=\"background-color: #c4c6c845; padding: 12px; border-radius: 6px;\"><strong>Sample Answer:<\/strong><br \/>Scrolling is handled using JavaScript execution. You can scroll to a specific position or until an element is in view. This helps when dealing with lazy-loaded content or fixed viewport sections.\n<pre><code>driver.execute_script(\"window.scrollTo(0, document.body.scrollHeight);\")\n<\/code><\/pre>\n<\/div>\n\n\n<h2 class=\"wp-block-heading has-background\" id=\"q21\" style=\"background-color:#b4e2ff\">Scenario-Based Python Selenium Questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"q21\">21. How would you test a login page using Selenium Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nLogin pages are one of the most common test scenarios. You validate field presence, input behaviour, error messages, and successful redirects. Always use locators that are stable (like `name`, `id`, or data attributes). Additionally, you should assert the landing page post-login using title or URL checks.<\/p>\n<pre><code># Locate elements\r\ndriver.find_element(By.ID, \"username\").send_keys(\"test_user\")\r\ndriver.find_element(By.ID, \"password\").send_keys(\"test_pass\")\r\ndriver.find_element(By.ID, \"loginBtn\").click()\r\n\r\n# Assertion\r\nassert \"dashboard\" in driver.current_url\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q22\">22. How do you handle CAPTCHA on a page while automating with Selenium?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nCAPTCHAs are intentionally designed to block bots. The best practice is to avoid automating flows where CAPTCHA is involved, or to disable them in test environments. If you must proceed, integrate third-party CAPTCHA solvers like 2Captcha, or handle the login manually before automation continues.<\/p>\n<p><em>Note: No Selenium code shown here as CAPTCHA bypassing often requires external service APIs and violates site terms.<\/em>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q23\">23. How do you test file uploads using Selenium with Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nYou can send the full file path directly to the input field of type &#8220;file&#8221;. This bypasses the OS-level file dialog and works for most modern browsers. Make sure your test file is accessible at runtime and avoid hard-coded paths.<\/p>\n<pre><code>upload = driver.find_element(By.ID, \"uploadInput\")\r\nupload.send_keys(\"\/path\/to\/testfile.pdf\")\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q24\">24. How do you automate a dynamic table and retrieve cell values in Selenium Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nDynamic tables change based on filters or pagination. Use XPath to target specific rows\/columns, or loop through table rows and extract data using tag names. Always use conditions to validate headers before parsing values.<\/p>\n<pre><code>rows = driver.find_elements(By.XPATH, \"\/\/table[@id='orders']\/tbody\/tr\")\r\nfor row in rows:\r\n    cols = row.find_elements(By.TAG_NAME, \"td\")\r\n    print(cols[0].text, cols[1].text)\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q25\">25. How do you validate a toast message or flash alert after form submission?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nToast or flash messages often appear briefly and may not be immediately in the DOM. Use `WebDriverWait` to wait for visibility or presence of the element. Use class names or ARIA roles for stable selectors.<\/p>\n<pre><code>toast = WebDriverWait(driver, 5).until(\r\n    EC.visibility_of_element_located((By.CLASS_NAME, \"toast-message\"))\r\n)\r\nassert \"Successfully saved\" in toast.text\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q26\">26. How would you test pagination functionality using Selenium Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nTesting pagination involves clicking on &#8220;Next&#8221;, &#8220;Previous&#8221;, or page numbers, and validating that the displayed results change accordingly. You can assert the text range or unique element per page.<\/p>\n<pre><code># Click Next\r\ndriver.find_element(By.LINK_TEXT, \"Next\").click()\r\nassert \"Page 2\" in driver.page_source\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q27\">27. How do you verify broken links using Selenium and Python?<\/h3>\n\n\n<div style=\"background-color: #c4c6c845; padding: 12px; border-radius: 6px;\"><strong>Sample Answer:<\/strong><br \/>Selenium alone can&#8217;t verify HTTP status codes, but you can extract all link URLs using Selenium and use Python\u2019s `requests` module to validate their response codes.\n<pre><code>import requests\n\nlinks = driver.find_elements(By.TAG_NAME, \"a\")\nfor link in links:\n    url = link.get_attribute(\"href\")\n    if url:\n        res = requests.head(url)\n        if res.status_code &gt;= 400:\n            print(\"Broken link:\", url)\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q28\">28. How do you test for responsive design using Selenium Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nResponsive testing involves setting different window sizes using `set_window_size()` and validating element visibility, layout changes, or class modifications across breakpoints.<\/p>\n<pre><code># Mobile viewport\r\ndriver.set_window_size(375, 667)\r\nassert driver.find_element(By.ID, \"hamburger-menu\").is_displayed()\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q29\">29. How do you verify email confirmation or OTP workflows in automation?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nThis cannot be done via Selenium alone. Use temporary email APIs (like Mailinator) or integrate with Gmail\/Outlook API to fetch email content. For OTPs, use DB hooks or stubs if the app supports it in test environments.<\/p>\n<p><em>Note: Email verification logic typically relies on API or IMAP scripting in parallel with Selenium.<\/em>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q30\">30. How would you test multi-window or tab handling in Selenium Python?<\/h3>\n\n\n<div style=\"background-color: #c4c6c845; padding: 12px; border-radius: 6px;\"><strong>Sample Answer:<\/strong><br \/>When a new tab opens, you need to switch Selenium\u2019s control to the new window using `window_handles` and `switch_to.window()`. Always validate titles or unique elements before interacting.\n<pre><code>main_tab = driver.current_window_handle\ndriver.find_element(By.LINK_TEXT, \"Open Docs\").click()\ntabs = driver.window_handles\ndriver.switch_to.window(tabs[1])  # Switch to new tab\nassert \"Documentation\" in driver.title\n<\/code><\/pre>\n<\/div>\n\n\n<h2 class=\"wp-block-heading has-background\" id=\"q31\" style=\"background-color:#b4e2ff\">Framework and Automation Design<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"q31\">31. What are the key components of a Selenium test automation framework?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nA well-designed Selenium framework includes:<\/p>\n<p>&#8211; **Test Data Management**: Externalising test data using JSON, Excel, or YAML.<br \/>\n&#8211; **Object Repository**: Storing locators centrally using Page Object Model.<br \/>\n&#8211; **Logging and Reporting**: Using tools like `logging`, `Allure`, or `HTMLTestRunner`.<br \/>\n&#8211; **Assertions**: Using `unittest`, `pytest`, or `assert` statements.<br \/>\n&#8211; **Browser Driver Setup**: With cross-browser handling.<br \/>\n&#8211; **Test Runner**: Like `pytest`, `unittest`, or CI tools (Jenkins, GitHub Actions).<\/p>\n<pre><code># Example: Logging config\r\nimport logging\r\nlogging.basicConfig(level=logging.INFO)\r\nlogging.info(\"Test started\")\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q32\">32. What is the Page Object Model (POM) and why is it important?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nPOM separates test logic from UI element locators. Each page has a class, and all actions (like clicking buttons or fetching text) are methods inside that class. This promotes reusability, reduces code duplication, and improves maintainability.<\/p>\n<pre><code># login_page.py\r\nclass LoginPage:\r\n    def __init__(self, driver):\r\n        self.driver = driver\r\n        self.username = driver.find_element(By.ID, \"username\")\r\n    \r\n    def login(self, user, pwd):\r\n        self.username.send_keys(user)\r\n        self.driver.find_element(By.ID, \"password\").send_keys(pwd)\r\n        self.driver.find_element(By.ID, \"loginBtn\").click()\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q33\">33. How do you implement test data-driven testing in Selenium Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nData-driven testing uses external data sources like Excel, CSV, JSON, or YAML files. With `pytest.mark.parametrize`, you can feed multiple data sets into the same test function, reducing redundancy and increasing coverage.<\/p>\n<pre><code>@pytest.mark.parametrize(\"user, pwd\", [(\"admin\", \"admin123\"), (\"user\", \"user123\")])\r\ndef test_login(user, pwd):\r\n    LoginPage(driver).login(user, pwd)\r\n    assert \"dashboard\" in driver.current_url\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q34\">34. What are some best practices for designing a robust Selenium automation suite?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\n&#8211; Use POM to separate UI logic.<br \/>\n&#8211; Integrate waits (`WebDriverWait`) to prevent flakiness.<br \/>\n&#8211; Externalise config (URL, credentials, etc.) via `.env` or YAML.<br \/>\n&#8211; Use CI pipelines for automation.<br \/>\n&#8211; Capture screenshots on failure.<\/p>\n<pre><code># Screenshot on failure\r\ndriver.save_screenshot(\"fail_screenshot.png\")\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q35\">35. How can you implement reusable functions in Selenium framework?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nWrap common actions (e.g. click, type, wait) inside utility\/helper methods. This centralises error handling and logging, and keeps your test scripts clean and readable.<\/p>\n<pre><code># helpers.py\r\ndef click_element(driver, locator):\r\n    WebDriverWait(driver, 10).until(EC.element_to_be_clickable(locator)).click()\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q36\">36. What are hooks in Pytest and how do they help?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nPytest hooks like `conftest.py` enable setup and teardown logic across test sessions. You can define fixtures for browser setup, login, database connection etc. to reduce redundancy and ensure consistent test environments.<\/p>\n<pre><code># conftest.py\r\n@pytest.fixture\r\ndef browser():\r\n    driver = webdriver.Chrome()\r\n    yield driver\r\n    driver.quit()\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q37\">37. What is the role of `conftest.py` in a Selenium Pytest project?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\n`conftest.py` is a special file in Pytest where you declare fixtures and hooks. It is automatically discovered and applied across test files. For Selenium, it usually includes browser setup, login steps, and teardown routines.<\/p>\n<pre><code># Reuse browser fixture\r\ndef test_title(browser):\r\n    browser.get(\"https:\/\/example.com\")\r\n    assert \"Example\" in browser.title\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q38\">38. How do you generate reports in Selenium Python projects?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nYou can generate test reports using:<\/p>\n<p>&#8211; `pytest-html` for simple HTML reports<br \/>\n&#8211; `Allure` for rich, interactive reports<br \/>\n&#8211; Custom logging with `unittest` + `HTMLTestRunner`<\/p>\n<pre><code># Run with HTML report\r\npytest --html=report.html\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q39\">39. What is the use of `pytest.ini` in Selenium automation?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\n`pytest.ini` stores configurations like marker names, test paths, log levels, etc. It helps control the Pytest behaviour centrally, such as ignoring warnings, setting base URLs, or tagging tests.<\/p>\n<pre><code>[pytest]\r\nmarkers =\r\n    smoke: Quick checks\r\n    regression: Full suite\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q40\">40. How do you structure folders in a Selenium Python project?<\/h3>\n\n\n<div style=\"background-color: #c4c6c845; padding: 12px; border-radius: 6px;\"><strong>Sample Answer:<\/strong><br \/>A clean structure includes:\n<p>&#8211; `\/tests`: Test scripts<br \/>&#8211; `\/pages`: Page Object classes<br \/>&#8211; `\/utils`: Helpers and config<br \/>&#8211; `\/reports`: Screenshots &amp; logs<br \/>&#8211; `conftest.py`, `pytest.ini`: Root-level configs<\/p>\n<pre><code>project\/\n\u251c\u2500\u2500 tests\/\n\u251c\u2500\u2500 pages\/\n\u251c\u2500\u2500 utils\/\n\u251c\u2500\u2500 reports\/\n\u251c\u2500\u2500 conftest.py\n\u251c\u2500\u2500 pytest.ini\n<\/code><\/pre>\n<\/div>\n\n\n<h2 class=\"wp-block-heading has-background\" id=\"q41\" style=\"background-color:#b4e2ff\">Tricky Python Selenium Questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"q41\">41. How can you handle dynamic web elements that change every time the page loads?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nDynamic elements usually have IDs or classes that change at runtime. Use stable attributes like `name`, `placeholder`, partial `XPath`, or `CSS` based on `contains()` or `starts-with()` functions. Avoid hardcoded values and use explicit waits to ensure timing consistency.<\/p>\n<pre><code># Using XPath contains\r\nelement = driver.find_element(By.XPATH, \"\/\/input[contains(@id, 'user')]\")\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q42\">42. What if your script passes locally but fails on CI\/CD server like Jenkins?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nThis is often caused by environment differences. Common issues include:<\/p>\n<p>&#8211; Screen resolution mismatch<br \/>\n&#8211; Headless browser not behaving identically<br \/>\n&#8211; Missing WebDriver path or environment variables<br \/>\n&#8211; Test dependency not installed<br \/>\n&#8211; Timing issues not handled via waits<\/p>\n<p>Use headless mode with correct options and set consistent environments.<\/p>\n<pre><code># Headless Chrome\r\noptions = webdriver.ChromeOptions()\r\noptions.add_argument(\"--headless\")\r\ndriver = webdriver.Chrome(options=options)\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q43\">43. How do you capture browser logs in Selenium using Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nYou can enable logging preferences in ChromeOptions to fetch logs related to network, console, or performance. This helps identify JS errors or network failures during UI automation.<\/p>\n<pre><code>options = webdriver.ChromeOptions()\r\noptions.set_capability(\"goog:loggingPrefs\",  )\r\ndriver = webdriver.Chrome(options=options)\r\nlogs = driver.get_log(\"browser\")\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q44\">44. How would you verify if a file is downloaded successfully using Selenium?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nSelenium doesn&#8217;t track download progress. You must monitor the file system to check whether the expected file appears. Use Python\u2019s `os` module to scan the download directory and verify.<\/p>\n<pre><code># Check if file exists\r\nimport os\r\nfile_exists = os.path.exists(\"\/downloads\/report.csv\")\r\nassert file_exists\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q45\">45. Can you explain the difference between find_element and find_elements in Selenium?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\n&#8211; `find_element` returns the **first** matching WebElement and throws `NoSuchElementException` if not found.<br \/>\n&#8211; `find_elements` returns a **list** of all matching elements and returns an **empty list** if none are found. Use `find_elements` when multiple matches are expected.<\/p>\n<pre><code># Example\r\nelements = driver.find_elements(By.CLASS_NAME, \"btn\")\r\nprint(len(elements))\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q46\">46. How do you handle JavaScript alerts, confirms, and prompts?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nUse Selenium\u2019s `switch_to.alert` to work with JavaScript popups. You can accept, dismiss, or enter text into alerts depending on the type.<\/p>\n<pre><code>alert = driver.switch_to.alert\r\nprint(alert.text)\r\nalert.accept()  # or alert.dismiss(), alert.send_keys(\"value\")\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q47\">47. How do you automate a CAPTCHA-protected login page?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nCAPTCHAs are meant to prevent automation. You can:<\/p>\n<p>&#8211; Ask the dev team to disable CAPTCHA for automation environment<br \/>\n&#8211; Use third-party CAPTCHA solving services (not recommended for real projects)<br \/>\n&#8211; Skip CAPTCHA logic entirely for test accounts<\/p>\n<p>No ideal automation exists for CAPTCHA due to legal and ethical limitations.\n<\/p><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q48\">48. How do you retry a failed Selenium test automatically in Python?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nUse `pytest-rerunfailures` plugin to retry failed tests. This helps tackle flaky tests caused by UI timing or network hiccups.<\/p>\n<pre><code># Retry test 2 times\r\npytest --reruns 2 test_sample.py\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q49\">49. How do you validate text presence on a webpage?<\/h3>\n\n\n<div style=\"background-color:#c4c6c845;padding:12px;border-radius:6px;\">\n<strong>Sample Answer:<\/strong><br \/>\nUse `get_attribute`, `text`, or verify via XPath contains. Make sure you wait for the element before validation.<\/p>\n<pre><code>assert \"Welcome\" in driver.find_element(By.TAG_NAME, \"body\").text\r\n<\/code><\/pre>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"q50\">50. How do you handle stale element reference exceptions?<\/h3>\n\n\n<div style=\"background-color: #c4c6c845; padding: 12px; border-radius: 6px;\"><strong>Sample Answer:<\/strong><br \/>This occurs when the DOM changes after locating an element. Solution:\n<p>&#8211; Re-locate the element before interacting again<br \/>&#8211; Use explicit waits to wait until element is reattached<\/p>\n<pre><code># Retry locating\ntry:\n    driver.find_element(By.ID, \"submit\").click()\nexcept StaleElementReferenceException:\n    time.sleep(1)\n    driver.find_element(By.ID, \"submit\").click()\n<\/code><\/pre>\n<\/div>\n\n\n<div class=\"wp-block-group\" style=\"margin-top: 40px;\">\n  <h2 id=\"faqs\">Frequently Asked Questions<\/h2>\n  <details>\n \n        <summary><strong>\ud83d\udd3d What is Selenium in Python used for?<\/strong><\/summary>\n        <div style=\"margin-top: 8px;\">Selenium in Python is used for automating browser interactions\u2014ideal for testing UI flows, scraping content, or automating form submissions.<\/div>\n      <\/details>\n\n      <details>\n        <summary><strong>\ud83d\udd3d How do I install Selenium for Python?<\/strong><\/summary>\n        <div style=\"margin-top: 8px;\">Install it via pip:<br><code>pip install selenium<\/code>. Then download the required WebDriver like ChromeDriver or GeckoDriver.<\/div>\n      <\/details>\n\n      <details>\n        <summary><strong>\ud83d\udd3d Can Selenium run without opening a browser window?<\/strong><\/summary>\n        <div style=\"margin-top: 8px;\">Yes, using headless mode with options in Chrome or Firefox. This is useful for CI\/CD pipelines or non-GUI servers.<\/div>\n      <\/details>\n\n      <details>\n        <summary><strong>\ud83d\udd3d What are common exceptions in Selenium Python?<\/strong><\/summary>\n        <div style=\"margin-top: 8px;\">Typical exceptions include <code>NoSuchElementException<\/code>, <code>TimeoutException<\/code>, <code>StaleElementReferenceException<\/code>, and <code>ElementNotInteractableException<\/code>.<\/div>\n      <\/details>\n\n      <details>\n        <summary><strong>\ud83d\udd3d Is Selenium Python enough to get a QA job?<\/strong><\/summary>\n        <div style=\"margin-top: 8px;\">It\u2019s a great starting point. Most automation tester roles require Selenium skills\u2014adding PyTest, CI\/CD knowledge, and API testing improves your chances.<\/div>\n      <\/details>\n\n      <details>\n        <summary><strong>\ud83d\udd3d Can Selenium handle multiple browser tabs?<\/strong><\/summary>\n        <div style=\"margin-top: 8px;\">Yes. Use <code>driver.window_handles<\/code> and <code>driver.switch_to.window()<\/code> to switch between tabs.<\/div>\n      <\/details>\n\n      <details>\n        <summary><strong>\ud83d\udd3d Which Singapore companies hire for Selenium Python roles?<\/strong><\/summary>\n        <div style=\"margin-top: 8px;\">Hiring firms include Shopee, Sea Group, DBS Bank, Grab, Singtel, and GovTech\u2014especially for roles in QA automation and software testing.<\/div>\n      <\/details>\n    <\/div>\n  <\/details>\n<\/div>\n\n\n","protected":false},"excerpt":{"rendered":"<p>Selenium with Python has become one of the most sought-after skills in test automation roles today. From fintech startups to established MNCs like Grab, DBS Bank, and Shopee in Singapore, companies are hiring QA and SDET professionals proficient in Python Selenium automation. Whether you&#8217;re preparing for your first job or targeting advanced Selenium Python interview [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":48012,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[147],"tags":[],"class_list":{"0":"post-48009","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-interview-questions"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.foundit.sg\/career-advice\/wp-json\/wp\/v2\/posts\/48009","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.foundit.sg\/career-advice\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.foundit.sg\/career-advice\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.foundit.sg\/career-advice\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.foundit.sg\/career-advice\/wp-json\/wp\/v2\/comments?post=48009"}],"version-history":[{"count":16,"href":"https:\/\/www.foundit.sg\/career-advice\/wp-json\/wp\/v2\/posts\/48009\/revisions"}],"predecessor-version":[{"id":48041,"href":"https:\/\/www.foundit.sg\/career-advice\/wp-json\/wp\/v2\/posts\/48009\/revisions\/48041"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.foundit.sg\/career-advice\/wp-json\/wp\/v2\/media\/48012"}],"wp:attachment":[{"href":"https:\/\/www.foundit.sg\/career-advice\/wp-json\/wp\/v2\/media?parent=48009"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.foundit.sg\/career-advice\/wp-json\/wp\/v2\/categories?post=48009"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.foundit.sg\/career-advice\/wp-json\/wp\/v2\/tags?post=48009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}