如何通过<a>关闭popover/popup元素使用硒 [英] How to close popover/popup by <a> element using Selenium

查看:74
本文介绍了如何通过<a>关闭popover/popup元素使用硒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 https://www 开发 webscraper.grailed.com/designers/jordan-brand/hi-top-sneakers.当页面打开时,会出现一个用于登录的弹出窗口.搜索网页设计,我可以找到 X 元素来关闭浏览器,如下所示: temp = WebDriverWait(driver, 10).until(ec.visibility_of_element_located((By.CLASS_NAME, 'close'))).如果我更深入地研究这个,就会有一个 and 元素.我曾尝试在元素上使用 .click() (使用类close"),以及 SVG 和 path 元素.这些都没有关闭框,并且 X 没有按钮或其他此类元素.我该怎么做才能关闭此弹出框?我不确定是否需要找到一个类似按钮的元素来点击,但我找不到这样的元素.我看过几个问题和文章(https://stackoverflow.com/questions/61923909/trying-to-close-popover-python-selenium-glassdoor,https://sqa.stackexchange.com/questions/5310/how-to-close-pop-up-window-in-selenium-webdriver,https://saucelabs.com/resources/articles/the-selenium-click-command)但找不到解决方案.

I'm working on a webscraper for https://www.grailed.com/designers/jordan-brand/hi-top-sneakers. When the page has opened a popup for login comes up. Searching through the web design I can locate the X element to close the browser like so: temp = WebDriverWait(driver, 10).until(ec.visibility_of_element_located((By.CLASS_NAME, 'close'))). If I go more into this there is an and element. I have tried using .click() on the element (with class 'close'), as well as the SVG and path elements. None of these close the box, and there is no button or other element of this kind for the X. What can I do to close this popover? I'm not sure if I need to find a button-ish element to click, but I can't find one like that. I've looked at a couple of questions and articles (https://stackoverflow.com/questions/61923909/trying-to-close-popover-python-selenium-glassdoor, https://sqa.stackexchange.com/questions/5310/how-to-close-pop-up-window-in-selenium-webdriver, https://saucelabs.com/resources/articles/the-selenium-click-command) but can't find a solution.

推荐答案

您可以通过双击操作解决此问题

You can do double click with actions for resolving this problem

WebDriverWait(driver, 20).until(ec.visibility_of_element_located((By.XPATH, 
   '//a[@class = 'close']/*[name()='svg']')))

close =  driver.find_element_by_xpath("//a[@class = 'close']/*[name()='svg']")

actionChains = ActionChains(driver)
actionChains.double_click(close).perform()

以及用于此的 Java 代码:

And the Java code for this:

new WebDriverWait(driver, 20)
                .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@class = 'close']/*[name()='svg']")));

WebElement close = driver.findElement(By.xpath("//a[@class = 'close']/*[name()='svg']"));

Actions action = new Actions(driver);
action.doubleClick(close).build().perform();

这篇关于如何通过<a>关闭popover/popup元素使用硒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆