How to close pop up window in Selenium(如何在 Selenium 中关闭弹出窗口)
问题描述
无法关闭 http://www.cargo.lt/ 之后出现的弹出窗口负载.这是我得到的:
Can't close pop up window which appears right after http://www.cargo.lt/ loads. Here's what I've got:
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.get('http://www.cargo.lt/asp/index.asp?')
time.sleep(10)
driver.find_element_by_xpath('/html/body/div[36]/div/a').click()
我对如何编写自定义 xpath/css 路径不是很熟悉,现在只需单击检查元素并复制 xpath.我做错了什么?
I'm not very familiar with how to write custom xpath/css path and now just clicked on Inspect element and copied xpath. What I'm doing wrong?
多么愚蠢的错误.没有意识到当元素离开屏幕时 Selenium 无法点击它.刚刚添加了 driver.maximize_window() ,我所有的问题都消失了.谢谢大家的回答.不幸的是我还不能投票,因为我没有足够的积分......
What a stupid mistake. Didn't realize that when element is off screen Selenium can't click on it. Just added driver.maximize_window() and all my problems are gone. Thanks all for your answers. Unfortunately I can't vote yet, because I don't have enough points...
推荐答案
我试过你的代码它工作正常我不知道你有什么问题但是试试这个:driver.implicitly_wait(10)
插入:
i tried your code it's work fine i don't know whats you problem but
try this : driver.implicitly_wait(10)
insted of :
time.sleep(10)
这篇关于如何在 Selenium 中关闭弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Selenium 中关闭弹出窗口


基础教程推荐
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 筛选NumPy数组 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01