0

Consider the following page: https://www.cvs.com/shop/advil-pain-reliever-fever-reducer-ibuprofen-tablets-200mg-prodid-1040240?skuid=420321

When selecting a different format, like 100 CT, a new price shows up. Copy that URL and navigate to it, notice that it redirects back to the original 10 CT page.

I want to get the price of what's on the 100 CT page.

Here is my code, which clicks the right format, but when I try to reobtain the url I still get the 10 CT page.

    format_header =  browser.find_element_by_css_selector("ul.--horizontalScroll.gbcvs-c-variantSelectorList")
    items = format_header.find_elements_by_tag_name('li')

    format_count = 1
    for item in items:
        text = item.text
        if(text == '100 CT'):
            break
        else: 
            format_count += 1

    browser.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Count:'])[1]/following::label["+str(format_count)+"]").click()

    print(browser.current_url)

    browser.get(browser.current_url)

2 Answers 2

1

Here is the code that ran and found the price correctly. You can get the price by using print (driver.find_element_by_css_selector("p.shoppdp-c-productPricing__actual").text) enter image description here

Here is the method code for wait_until_element_not_present

def wait_until_element_not_present(locator_type,locator):
    if locator_type == 'xpath':
        WebDriverWait(driver, 10).until_not(EC.presence_of_element_located((By.XPATH, locator)))
    elif locator_type == "css":
        WebDriverWait(driver, 10).until_not(EC.presence_of_element_located((By.CSS_SELECTOR, locator)))
Sign up to request clarification or add additional context in comments.

2 Comments

Which library contains "wait_until_element_not_present"? selenium-python.readthedocs.io/waits.html
Instead of passing the locator type and the locator as strings, pass it as a triplet as in this answer. Now you don't have to parse the locator type and deal with each one differently. It turns your function into a one-liner which is easier to manage and more flexible.
0

@supputuri's answer is the correct one, only I replaced wait_until_element_not_present by the following

    WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.CLASS_NAME, "gbcvs-c-addToCart__inner"))
    )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.