Handling Pop-up Windows in Python with Selenium

# Automation Setup

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchAttributeException, NoAlertPresentException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

import time

# Setting the path for Chrome driver
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

# Opening Badoo website
driver.get("https://am1.badoo.com/sv/mobile/")
driver.maximize_window()

username = "*************"
password = "*************"
print(driver.title)
time.sleep(5)

# Logging in
search = driver.find_element_by_xpath('//*[@id="header"]/div/div[2]/div/div[2]/a')
search = driver.find_element_by_partial_link_text('Logga in')
search.send_keys(Keys.RETURN)

time.sleep(5)

print("Logging in")
search = driver.find_element_by_name('email')
search.send_keys(username)
search = driver.find_element_by_name('password')
search.send_keys(password)

time.sleep(2)
search = driver.find_element_by_xpath('//*[@id="page"]/div[1]/div[3]/section/div/div/div[1]/form/div[5]/div/div[1]/button').click()
time.sleep(5)
# Clicking on the like button
search = driver.find_element_by_xpath('//*[@id="mm_cc"]/div[1]/section/div/div[2]/div/div[2]/div[1]/div[1]').click()
time.sleep(1)

# Handling popup
search = driver.switch_to.alert

message=search.text
print ("Alert shows following message: "+ message )
time.sleep(2)
search.dismiss()

I am struggling to handle a popup while automating interactions with the Badoo dating application. The popup appears when you like someone, and I need help figuring out how to interact with it by clicking accept or decline.

Can anyone provide guidance on this issue?

Thank you in advance :)

Screenshots of the popup can be viewed here: https://i.sstatic.net/jWSNp.png

Unfortunately, I am unable to copy the HTML code, but screenshots are available here: https://i.sstatic.net/EDIxu.jpg https://i.sstatic.net/xLNww.jpg

Answer №1

When faced with a consistent popup message that appears in the same location and format each time, consider utilizing pyautogui, a Python library, to locate the popup and automatically navigate the mouse cursor to the "No" button for a quick dismissal.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Spacing between products in Woocommerce product list

Welcome to my website! Check it out here: I am facing an issue with a long margin at the bottom of my woocommerce product list. I have tried using CSS to change it as shown below: .woocommerce .products ul, .woocommerce ul.products { margin-bot ...

Locating elements using Ruby Selenium Web Driver without triggering a NoSuchElementException异常

I am currently testing the following HTML using Ruby Selenium Web Driver: <div class="container-fluid container-results"> <div class="result-row" id="0"> <ul> <li class="process-status-column upload-success-ico ...

What is the best way to prevent the table from being added again once it has been displayed?

I'm faced with the task of displaying an HTML table in a popup window when a button is clicked, using Bootstrap modal functionality. This scenario is similar to a preview function where user input is displayed in a table when a preview button is click ...

Is it possible to modify a single entry in a series of records?

I have a list of data entries, such as addresses, and I am currently displaying them using the following combination of html5 and knockout code. <section id="lists" data-bind="foreach: addresses, visible: addresses().length > 0"> <article& ...

Getting the true height without needing jQuery

let element = document.getElementById('test'); console.log(element.scrollHeight); <div style="height: 30px;" id="test"> <p>ffffffffff</p> <p>gggggggggg</p> ...

Attempting to recreate the dynamic banner featured in the video

Looking to replicate a setup similar to what was demonstrated in the video. I have two div blocks - one with a random image and the other with a video, and I want them to be as flexible and identical as possible to the video layout. How should I go about a ...

Utilizing Stylus: Embracing Interpolation within a Mixin

I am encountering an issue while attempting to interpolate values passed into a mixin. positionModifier( key, x, y) &.{key} background-position: {x}px {y}px; An error is being thrown, which is shown below: 351| positionModifie ...

It appears that the JS function is not being triggered

I am facing an issue with my JavaScript code where a ball is not showing up even though it should. I have an array with only one element, and when that element matches with "F2", the ball is supposed to appear. I suspect there might be a problem with my us ...

Query CSS to target an empty array within the .data() method

I have a scenario where I am storing an array in a button using Jquery's .data() method. If the array happens to be empty, I want the button to appear in red color. How can I target the button with an empty array using CSS? var values1 = []; var ...

Scrapy: navigating through dynamically-loaded content using the "Expand" feature

I am currently attempting to scrape data from a webpage similar to this: https://www.newsweek.pl/nwpl_2018002_20181231. On the page, there is a "More" (in Polish, Więcej) button at the bottom that dynamically loads additional articles. I would like to uti ...

Having trouble with setting the date in Firefox 57 using Selenium 3.4?

Date Field Image Having trouble setting date information beyond the specified date field using the sendKeys function. Attempted to use JavaScript but unable to successfully set the value. Update: HTML driver.findElementBy("//label[text()='Past Spe ...

Function for editing a button in an AngularJS single page application

I am a beginner in AngularJS and I'm currently working on a project to create a single page application for tracking expenses. However, I'm facing some challenges with my code. Although I have successfully implemented most of the functions, I am ...

Tips for creating animations with JavaScript on a webpage

I created a navigation bar for practice and attempted to show or hide its content only when its title is clicked. I successfully toggled a hidden class on and off, but I also wanted it to transition and slide down instead of just appearing suddenly. Unfort ...

Angular functions are executed twice upon being invoked within the html file

I decided to kick-start an Angular project, and I began by creating a simple component. However, I encountered a perplexing issue. Every time I call a function in the HTML file from the TypeScript file, it runs twice. TS: import { Component, OnInit } from ...

Ways to adjust the size of an HTML fieldset?

Is there a way to decrease the space between the paragraph and the border of this fieldset? I attempted to adjust the margins in the following manner: fieldset { margin: 1px; margin-top: 2px; border-top-right-radius: 1px; } <fieldset> < ...

What is the process for setting up distinct radio types that will be separated?

I'm attempting to generate two separate questions with radio buttons in HTML. However, whenever I test it, I can only select one option even though I used to separate the questions to prevent interaction. Can anyone assist me? Do you agree? Yes ...

What is the best way to control the visibility of content using CSS based on the screen size?

Similar to Bootstrap, Ionic (specifically Ionic 3) allows for resizing column widths based on screen size using classes like col-sm-8, col-md-6, col-lg-4. Bootstrap also includes classes such as visible-xs, hidden-sm, etc. for displaying or hiding conten ...

Implementing page load in Selenium WebDriver 2.0 using Java

Is there a way to make Selenium wait for the page to load properly in my application? I've tried using the Thread.sleep(5000) method and sometimes it works well, but other times it doesn't. Can someone please help me out with this issue? Thanks, ...

Tips for aligning the box beside another

How can I arrange 2 boxes in one line and the other 2 in the next line? Currently, they are all showing up on separate lines. Can anyone provide a solution to this issue? body{ background:#f4f4f4; color:#555; font-family:Bahnschrift SemiCond ...

Each time I use console.log to display a user's radio button choice, the output is consistently lagging by one step

It seems that I am experiencing an issue where the console.log output for a user's radio button selection is always one step behind. This occurs even though I have initially set the default radio button selection to "all". For example, when a user cli ...