-1

So i got this code that should login to nike and then do some other stuff but taths not so important right now. Heres is the code:

    try:
        LOGGER.info("Requesting page: " + NIKE_URL)
        driver.get(NIKE_URL)
    except TimeoutException:
        LOGGER.info("Page load timed out but continuing anyway")

    #We swith to the MEN tab here to simulate user interaction, because the "login" button doesn't always show
    LOGGER.info("Waiting for Men button to become clickable")
    wait_until_clickable(driver=driver, xpath="//a[@class='pre-desktop-menu-link headline-5 prl3-lg pt4-sm d-sm-b no-outline']", duration=10)

    LOGGER.info("Clicking men button")
    driver.find_element("xpath", "//a[@class='pre-desktop-menu-link headline-5 prl3-lg pt4-sm d-sm-b no-outline']").click()

    #LOGGER.info("Waiting for men label to be visible")
    #wait_until_visible(driver=driver, xpath="//span[@class='nike-cq-subtitle-line-1 nike-cq-title-line nike-cq-line1 nsg-text--dark-grey nike-cq-font60px nike-cq-nospacing nsg-font-family--platform']")

    LOGGER.info("Waiting for login button to become clickable")
    wait_until_clickable(driver=driver, xpath="//button[@class='nav-btn p0-sm d-sm-b body-4 u-bold ml2-sm mr2-sm']", duration=10)

    LOGGER.info("Clicking login button")
    driver.find_element("xpath", "//button[@class='nav-btn p0-sm d-sm-b body-4 u-bold ml2-sm mr2-sm']").click()

    LOGGER.info("Waiting for login fields to become visible")
    wait_until_visible(driver=driver, xpath="//input[@name='emailAddress']")

    LOGGER.info("Entering username and password")
    email_input = driver.find_element_by_xpath("//input[@name='emailAddress']")
    email_input.clear()
    email_input.send_keys(username)
    password_input = driver.find_element_by_xpath("//input[@name='password']")
    password_input.clear()
    password_input.send_keys(password)

    LOGGER.info("Logging in")
    driver.find_element_by_xpath("//input[@value='ANMELDEN']").click()
    wait_until_visible(driver=driver, xpath="//span[text()='Mein Konto']")

    LOGGER.info("Successfully logged in")

def wait_until_clickable(driver, xpath=None, class_name=None, duration=10000, frequency=0.01):
    if xpath:
        WebDriverWait(driver, duration, frequency).until(EC.element_to_be_clickable((By.XPATH, xpath)))
    elif class_name:
        WebDriverWait(driver, duration, frequency).until(EC.element_to_be_clickable((By.CLASS_NAME, class_name)))


def wait_until_visible(driver, xpath=None, class_name=None, duration=10000, frequency=0.01):
    if xpath:
        WebDriverWait(driver, duration, frequency).until(EC.visibility_of_element_located((By.XPATH, xpath)))
    elif class_name:
        WebDriverWait(driver, duration, frequency).until(EC.visibility_of_element_located((By.CLASS_NAME, class_name)))

def select_shoe_size(driver, shoe_size):
    LOGGER.info("Waiting for size dropdown button to become clickable")
    wait_until_clickable(driver, xpath="//select[@id='skuAndSize']", duration=10)

    LOGGER.info("Clicking size dropdown button")
    driver.find_element_by_id("skuAndSize").click()

    LOGGER.info("Waiting for size dropdown to appear")
    wait_until_clickable(driver, xpath="//select[@id='skuAndSize']/option", duration=10)


    LOGGER.info("Selecting size from dropdown")
    driver.find_element_by_id("skuAndSize").find_element_by_xpath("//option[text()='{}']".format(shoe_size)).click()

def click_buy_button(driver):
    LOGGER.info("Waiting for buy button to become clickable")
    wait_until_clickable(driver, xpath="//button[@class='ncss-btn-black fs16-sm ncss-base u-medium pb3-sm prl5-sm pt3-sm css-y0myut addToCartBtn']", duration=10)

    LOGGER.info("Clicking buy button")
    driver.find_element_by_xpath("//button[@class='ncss-btn-black fs16-sm ncss-base u-medium pb3-sm prl5-sm pt3-sm css-y0myut addToCartBtn']").click()

def click_submit_button(driver):
    xpath = "//button[text()='Submit Order']"

    LOGGER.info("Waiting for submit button to become clickable")
    wait_until_clickable(driver, xpath=xpath, duration=10)

    LOGGER.info("Clicking submit button")
    driver.find_element_by_xpath(xpath).click()

def click_cart_icon(driver):
    xpath = ""

def main():
    parser = argparse.ArgumentParser(description='Processing input values for run')
    parser.add_argument("--username")
    parser.add_argument("--password")
    parser.add_argument("--url")
    parser.add_argument("--shoe_size")
    parser.add_argument("--login_time", default=None)
    parser.add_argument("--release_time", default=None)
    parser.add_argument("--screenshot_path", default=None)
    parser.add_argument("--html_path", default=None)
    parser.add_argument("--page_load_timeout", type=int, default=2)
    parser.add_argument("--driver_type", default="chrome", choices=("firefox", "chrome"))
    parser.add_argument("--headless", action="store_true")
    parser.add_argument("--select_payment", action="store_true")
    parser.add_argument("--purchase", action="store_true")
    parser.add_argument("--num_retries", type=int, default=1)
    args = parser.parse_args()
    driver = None

    if args.driver_type == "chrome":
        options = webdriver.ChromeOptions()
        if args.headless:
            options.add_argument("headless")
        if sys.platform == "win32":
            executable_path = "./bin/chromedriver.exe"
        else:
            raise Exception("Unsupported operating system. Please add your own Selenium driver for it.")
        driver = webdriver.Chrome(executable_path=executable_path, options=options)
    else:
        raise Exception("Unsupported browser. Please use chrome for now")

    run(driver=driver, username=args.username, password=args.password, url=args.url, shoe_size=args.shoe_size,
        login_time=args.login_time, release_time=args.release_time, page_load_timeout=args.page_load_timeout,
        screenshot_path=args.screenshot_path, html_path=args.html_path, select_payment=args.select_payment,
        purchase=args.purchase, num_retries=args.num_retries)

Everything works until to the point where it should log in here are the logs:

2022-09-14 21:27:35,570 [PID 5096] [Thread 3292] [INFO] [root] Requesting page: https://www.nike.com/de/de_de 2022-09-14 21:27:37,578 [PID 5096] [Thread 3292] [INFO] [root] Page load timed out but continuing anyway 2022-09-14 21:27:37,579 [PID 5096] [Thread 3292] [INFO] [root] Waiting for Men button to become clickable 2022-09-14 21:27:37,763 [PID 5096] [Thread 3292] [INFO] [root] Clicking men button 2022-09-14 21:27:39,868 [PID 5096] [Thread 3292] [ERROR] [root] Failed to login: Message: timeout: Timed out receiving message from renderer: 2.000

Does someone knows how to fix this problem

Noam
  • 1
  • 2

1 Answers1

1

On the line where you have --page_load_timeout, you set the timeout to 2 seconds, which is very, very low. (If you don't set a page_load_timeout at all, it defaults to 300 by default for Selenium.) That is the maximum time that the browser will wait for a page load to complete before throwing an error. To get around that, I would set that timeout much higher... to 30 at a minimum.

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48
  • now i get this error: `` [PID 13200] [Thread 2184] [ERROR] [root] Failed to login: Message: element click intercepted: Element is not clickable at point (1081, 66). Other element would receive the click: ``` – Noam Sep 15 '22 at 13:31
  • For that, see https://stackoverflow.com/questions/11908249/debugging-element-is-not-clickable-at-point-error - You may have an overlay that is blocking your click. – Michael Mintz Sep 15 '22 at 13:41