This web scraping already works to change aliexpress countries and currencies, but only if I click on the page manually before the pop-up appears and I can't understand why this is happening.
This is my code:
from selenium import webdriver
from os import getcwd
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
option = webdriver.ChromeOptions()
prefs = {
"translate_whitelists": {"es": "en"},
"translate": {"enabled": "true"},
"profile.default_content_setting_values.notifications": 2
}
option.add_experimental_option("prefs", prefs)
option.add_argument("start-maximized")
option.add_argument("--lang=en")
driver = webdriver.Chrome(executable_path=f"{getcwd()}\chromedriver.exe", options=option)
driver.switch_to.window(driver.current_window_handle)
url = input("Type a aliexpress url: ")
driver.get(url)
# close aliexpress coupon pop-up
WebDriverWait(driver, 20).until(
EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[contains(@src, '__poplayer')]")))
time.sleep(5)
for i in driver.find_elements_by_xpath("//img[contains(@src, 'http')]"):
i.click()
driver.switch_to_default_content()
# change country to india and currençy to usd
driver.find_element_by_xpath("//a[contains(@class, 'switcher-info')]/span[@class='ship-to']/i").click()
time.sleep(5)
driver.find_element_by_class_name("switcher-common").find_elements_by_tag_name("a")[0].click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.XPATH, "//li[@class='address-select-item']//span[@class='shipping-text' and text()='India']"))).click()
driver.find_element_by_class_name("switcher-common").find_elements_by_class_name("switcher-currency-c")[1].click()
driver.find_elements_by_xpath("//div[@class='search-container']//input[@class='search-currency']")[1].send_keys("usd")
driver.find_element_by_xpath("//a[@data-currency='USD']").click()
driver.find_element_by_class_name("switcher-common").find_elements_by_tag_name("button")[0].click()
when I don't click, it return this error:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
I already try to click in a random place like the navbar at the top, but it return a error saying that the pop-up have obscured it. So, as the pop-up appears inside the body, I tried to click on it with: driver.find_element_by_css_selector("body")
, but nothing changes.