【问题标题】:Python Selenium PopupPython Selenium 弹出窗口
【发布时间】:2021-07-15 19:35:26
【问题描述】:
# 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

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)




driver.get("https://am1.badoo.com/sv/mobile/")
driver.maximize_window()

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

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("Login 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)
# klickar på like knappen
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)

#popup
#Switch the control to the Alert window
search = driver.switch_to.alert

#Retrieve the message on the Alert window
message=search.text
print ("Alert shows following message: "+ message )
time.sleep(2)
# Or Dismiss the Alert using
search.dismiss()

嘿,我的问题是我无法理解如何处理弹出窗口。试图为 badoo 约会应用程序自动化。当你喜欢第一人称时,会出现一个弹出窗口。但我找不到或无法确定如何连接该弹出窗口,因此我可以单击拒绝/接受。

谁能帮帮我?

提前致谢:)

弹出画面:

无法弄清楚如何复制 html 代码,但这是它的屏幕:

【问题讨论】:

  • 可以分享HTML代码吗?我们无法登录随机网站。
  • Wasen't Abel 从页面复制 html 代码,但我添加了它的屏幕。弹出部分突出显示。希望它有助于理解我的问题。

标签: html css selenium selenium-webdriver


【解决方案1】:

如果每次弹窗的文字和格式都一样,可以使用pyautogui(python库)检测弹窗,将鼠标移动到“Nej”的位置点击。

【讨论】: