如何在 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)
相关文章