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 中关闭弹出窗口
基础教程推荐
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
