Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 22, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 22, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 22, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 22, 2025

      Sam Altman says ChatGPT’s viral Ghibli effect “forced OpenAI to do a lot of unnatural things”

      May 22, 2025

      How to get started with Microsoft Copilot on Windows 11

      May 22, 2025

      Microsoft blocks employees from sending emails that mention “Palestine” or “Gaza”

      May 22, 2025

      I missed out on the Clair Obscur: Expedition 33 Collector’s Edition but thankfully, the developers are launching something special

      May 22, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Perficient is Shaping the Future of Salesforce Innovation

      May 22, 2025
      Recent

      Perficient is Shaping the Future of Salesforce Innovation

      May 22, 2025

      Opal – Optimizely’s AI-Powered Marketing Assistant

      May 22, 2025

      Content Compliance Without the Chaos: How Optimizely CMP Empowers Financial Services Marketers

      May 22, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Sam Altman says ChatGPT’s viral Ghibli effect “forced OpenAI to do a lot of unnatural things”

      May 22, 2025
      Recent

      Sam Altman says ChatGPT’s viral Ghibli effect “forced OpenAI to do a lot of unnatural things”

      May 22, 2025

      How to get started with Microsoft Copilot on Windows 11

      May 22, 2025

      Microsoft blocks employees from sending emails that mention “Palestine” or “Gaza”

      May 22, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Unable to capture the alert in Selenium using Python

    Unable to capture the alert in Selenium using Python

    November 13, 2024

    I am trying to test a web portal using Selenium and Python. The problem is, I am unable to get around an error, in other words, I am unable to catch the alert.

    Scenario:

    Search for a user, if the user is not found, the website throws an error. I have a list that contains valid and invalid users to perform the search upon. When the search is successful, there are a few links I need to click to get to the user. If the user is not found, the links won’t be displayed and an error is displayed instead. The problem is when I search for an invalid user, the code is looking for the links that are displayed when the a valid user is displayed.

    Code:

    from selenium import webdriver
    from selenium.webdriver.chrome.webdriver import WebDriver
    from selenium.webdriver.support.select import Select
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.support.ui import Select
    from selenium.common.exceptions import TimeoutException
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.alert import Alert
    from selenium.common.exceptions import NoAlertPresentException
    import time
    
    browser = webdriver.Chrome()  # type: WebDriver is Chrome
    browser.get("https:URL")
    
    
    
    if option == 'number':
                nums = ['111', '123', '456']
                searchbox = browser.find_element_by_id("searchPattern")
                noUser = browser.find_element_by_xpath('//*[@id="includeError"]/div')
                try:
                    for num in nums:
                        searchbox.send_keys(num)
                        browser.find_element_by_xpath('//[@id="User"]/input[2]').click()
                        time.sleep(4)
                        user_links = ['photos', 'message', 'mails']
                        for url in user_links:
                            if url in user_links:
                                browser.find_element_by_link_text(url).click()
                                time.sleep(4)
                            elif url not in user_links:
                                print "No users found"
                        browser.switch_to_window(browser.window_handles[0])
                        time.sleep(5)
                        browser.find_element_by_id('searchPattern').clear()
                except noUser:
                    print "no users"
    

    Source: Read More

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleLoad testing on CI/CD Teamcity with Jmeter
    Next Article Problems to execute a UFT script by a VBScript file

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 23, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-47512 – Tainacan Path Traversal

    May 23, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    ZFS Raidz Expansion Finally, Here in version 2.3.0

    Linux

    Forget cheap multitools. My favorite brand is repairable with a 25-year warranty

    News & Updates

    Implementing Knowledge Bases for Amazon Bedrock in support of GDPR (right to be forgotten) requests

    Development

    Streamline custom model creation and deployment for Amazon Bedrock with Provisioned Throughput using Terraform

    Development

    Highlights

    Bringing Web Designs to Life

    August 7, 2024

    In today’s digital landscape, a website’s design is crucial in capturing users’ attention and keeping…

    Hierarchical Graph Masked AutoEncoders (Hi-GMAE): A Novel Multi-Scale GMAE Framework Designed to Handle the Hierarchical Structures within Graph

    May 29, 2024

    Universal speech-to-text model leads in English, German, and Spanish

    February 20, 2025

    CVE-2025-4176 – PHPGurukul Blood Bank & Donor Management System SQL Injection Vulnerability

    May 1, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.