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 中关闭弹出窗口


- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01