0

Refer to this page:https://www.lanebryant.com/gold-sequin-v-neck-top/prd-358677#color/0000012216

Click on What's my size and you'll get 'get started' button. I am trying to click that but it gives timeout exception.

 size = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH,

                                                                       "//button[@class='tfc-cfg-next-button tfc-auto-next-button tfc-button tfc-element tfc-click']")))

Edit I have already clicked the popup that the button is in

 size = WebDriverWait(browser, 2).until(EC.element_to_be_clickable((By.XPATH,

                                                                     "//a[@class='tfc-popup-click-open']")))


 browser.execute_script("arguments[0].click();", size)

I have tried multiple ways to switch to popup one of which is:

       main_page = browser.current_window_handle
        # changing the handles to access login page
        login_page = None
        for handle in browser.window_handles:
            if handle != main_page:
                login_page = handle
        browser.switch_to.window(str(login_page))

        try:
                browser.find_element_by_xpath("/html/body/div[2]/div/div/div/div[2]/div[2]/tfc-button-bar/div/div/tfc-next-button/span/span/button").Enabled
        except:
                pass

Still not working

Fatima Arshad
  • 119
  • 1
  • 9

2 Answers2

0

To anyone who is new like me and can't find the answer. This is the solution:

driver.switch_to.frame(driver.find_element_by_css_selector("body > div.tfc-modal-result.tfc-secure.tfc-cfg-core.tfc-language-en.tfc-shopping-for-self.tfc-sfo-disabled.tfc-discovery-disabled.tfc-sfo-unavailable.tfc-discovery-unavailable.tfc-department-adults > div > iframe"))

The problem was I couldn't find name or ID or class for iframe to refer to it. It didn't occur to me to just copy css selector directly from Chrome(Click on inspect. Right click and copy>selector)

Fatima Arshad
  • 119
  • 1
  • 9
0

This is the way I just solved the problem:

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

driver=webdriver.Chrome("C:\webdrivers\chromedriver.exe")
driver.maximize_window()
driver.get("https://www.lanebryant.com/gold-sequin-v-neck-top/prd-358677#color/0000012216")
driver.find_element_by_xpath("//*[@id='button']/button").click()

driver.refresh()
sizeLink = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//a/span[2]/span[2]")))
sizeLink.click()
iframe = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "/html/body/div[25]/div/iframe")))
driver.switch_to_frame(iframe)
getStarted = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//span/span/button/span")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable,getStarted)
getStarted.click()

The first click is to get rid of a country specific popup window which appears in my case.

The Xpath expressions I'm using are relative instead of the absolute XPaths you are using.

Frank
  • 831
  • 1
  • 11
  • 23