0

if I click any of menu on this page it will show menu info. But how I can close the popup ? see the screenshot enter image description here

I tied those code but didn't work. driver.find_element_by_css_selector('.styles__ActionWrapper-sc-v9lptc-1 svg') , driver.find_element_by_xpath("//div[@class='styles__ActionWrapper-sc-v9lptc-1 eekxlt']")

boyenec
  • 1,405
  • 5
  • 29
  • Can you share with us a dummy address to get around the **Enter Your Delivery Address** popup, with current location (outside US) the popup won't allow to click on any menu within. – undetected Selenium Aug 07 '22 at 21:54
  • If you are outside from US then you need to use VPN for access the site. You don't need to provide any dummy address. just click the link and it will take you the page – boyenec Aug 07 '22 at 22:00
  • Incase you update the question with the text based HTML of the element, let me know, I can give it a go... – undetected Selenium Aug 07 '22 at 22:03
  • 1
    @undetectedSelenium the pop-up asking for `Your Delivery Address` has exactly the same element :) – Prophet Aug 07 '22 at 22:04

4 Answers4

0

As I see

driver.find_element_by_css_selector('.styles__ActionWrapper-sc-v9lptc-1 button')

Or

driver.find_element_by_xpath("//div[@class='styles__ActionWrapper-sc-v9lptc-1 eekxlt']/button")

Should work, but you have to add a delay to make these elements fully loaded before clicking them.
The best way is to use visibility_of_element_located expected condition explicit wait.
Like this:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 20)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".styles__ActionWrapper-sc-v9lptc-1 button"))).click()
Prophet
  • 32,350
  • 22
  • 54
  • 79
0

The desired element is a dynamic element, so to click on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[class^='styles__ActionWrapper'] button[class^='styles__StyledButtonRoot']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[starts-with(@class, 'styles__ActionWrapper')]//button[starts-with(@class, 'styles__StyledButtonRoot')]"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    just to understand: how your answer actually differs from my? Especially after the author wrote he is trying to click after the page is fully loaded i.e. no need to add any waits. – Prophet Aug 07 '22 at 22:17
  • @Prophet There are several differences and the major one being, you are considering the all the _`classnames`_ where some of them are dynamically generated, where as I have considered the static ones. Second and most important, while answering our focus shouldn't only cover OP's specific usecase. Rather answers should be helpful to the future visitors as well. Better not to assume all the future visitor will notice the clause _trying to click after the page is fully loaded_ but take care of the situation. – undetected Selenium Aug 07 '22 at 22:23
  • Well, let's see if this answer will work better for the author. – Prophet Aug 07 '22 at 22:25
0

I'm sure the other two answers are fine (I didn't test them, but I suppose their authors did) but here is my take on the whole issue, difference being the way I select the item as seen from a US connection:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@aria-label = 'Close Combo #1']"))).click()

This assumes you selected Combo #1 from the menu. You can change that locator dynamically, depending on the menu selected.

Barry the Platipus
  • 9,594
  • 2
  • 6
  • 30
0
ChromeOptions options = new ChromeOptions()

options.setExperimentalOption("excludeSwitches",

 Arrays.asList("disable-popup-blocking"))

Try this code

eymentakak
  • 90
  • 8