0

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.

Norayr Sargsyan
  • 1,737
  • 1
  • 12
  • 26
Eric Hasegawa
  • 169
  • 1
  • 14

2 Answers2

1

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()

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();
Norayr Sargsyan
  • 1,737
  • 1
  • 12
  • 26
  • I get the following error: ```AttributeError: 'ActionChains' object has no attribute 'build'```. If I remove the .build() it works fine. – Eric Hasegawa Jul 02 '20 at 20:55
1

I actually just ran into the same issue myself. The above solution didn't work for me, so I'll post what I did here:

Essentially, I clicked by the coordinates instead of by trying to find the button element.

Note: some webpages don't display the popup until you try to click something else, so I had to first attempt to click another element. If you need to do that, make sure to wait a second or so for the popup to load.

Then, you can do the rest via ActionChain:

elem = driver.find_element_by_class_name("CLASSNAME")    
ac = ActionChains(driver)
ac.move_to_element(elem).click().perform()

You'll want to encase this in a try-except block for extra safety.

Credit to Dirk Bergstrom for providing part of the solution here: Clicking at coordinates without identifying element

  • Web links tend to decay over time, so if you could copy-paste the info that's relevant from Dirk Bergstrom's site, that would be awesome. – Henry Crutcher Oct 16 '20 at 13:04