Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)
recategorized by

I am webscraping https://www.virginmobile.ca/en/phones/phone-details.html#!/a70/Black/128/MTH. I am trying to grab the pricing under 'PICK YOUR MONTHLY PHONE PLAN' however as I select the 'buy your phone upfront' option the plans below have a 'see more plans' button which I am attempting to click. I managed to click it it however sometimes there is still more plans to be seem and my while loop doesnt seem to click it if the button still exists. instead the trace states:

Element showitems" ng-click="showmoreplans()" ng-bind-html="messages['phonedetail.seemoreplan.label']" class="ng-binding ng-scope">... is not clickable at point (620, 870). Other element would receive the click: ...

    for planType in planTypeRawList:

        planPriceList = []

        ActionChains(driver).move_to_element(planType).click().perform()

        time.sleep(0.5)

        while True:

            try:

                see_more_plans = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, '#planList > a')))

                see_more_plans[0].click()

                print('see More Clicked')

                time.sleep(0.5)

            except TimeoutException:

                break

        planPriceListRaw = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, '#planList .price')))

        for price in planPriceListRaw:

            planPrice = price.text

            planPriceList.append(planPrice)

        print(planPriceList)

        print('end of plan type')

I would ultimately like to be able to click the 'see more plans' option as much times as it pops up and then move on to scrape after all the plans are visible and the button disappears.

1 Answer

0 votes
by (25.1k points)

Use the following code to scroll to the element you wish to click

see_more_plans = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, '#planList > a')))

driver.execute_script("arguments[0].click();",see_more_plans[0])

print('see More Clicked')

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...