pythonbuttonselenium-chromedriverscreen-scraping

Python Clicking Redfin Favorite and X-Out Button


For personal use I want to click on the Favorites or X-Out buttons of Redfin with my Python Selenium code, but I can't programmatically locate either button and I've tried for 2 days. I can see buttons with Chrome inspector but I can't locate them with the code and I've tried everything, I really have. I am just stuck and need help.

Please show me how I can locate each button, identify their selection status (selected/unselected) and how to click on them to make them toggle the selection back and forth.

I'm not new to Python or Selenium, but I am really stumped on this one. I'm accessing Chrome using the remote debugging method, which is really nice once you get it figure out. It lets me log in using my Google account, otherwise it was impossible to login like that using Selenium.

Thanks for your help.

Here is a test link https://www.redfin.com/TX/Roanoke/61-Cortes-Dr-76262/home/169577463 and html snippet from the site:

<div class="actions force-sideBarRightRail">
<div class="bp-HomeControls">
<div class="bp-pill-container-variant">
<div class="FavoriteButtonCopFlyoutWrapper HomeControlButtonWrapper">
<div class="bp-favoriteButtonWrapper bp-HomeActionsButton" data-rf-test-id="abp-favoriteButton">
<button type="button" class="bp-Button bp-homeActionButton bp-Button__type--ghost bp-Button__size--compact" tabindex="0" aria-label="Favorite this home">
<span class="ButtonIcon">
<svg class="bp-SvgIcon favorite bp-SvgIcon__size--medium">
<svg viewBox="0 0 24 24">
<path fill-rule="evenodd" clip-rule="evenodd" d="a bunch of number here"/>
</svg>
</svg>
</span>
<span class="ButtonLabel">
Favorite</span>
</button>
</div>
</div>
<div class="HomeControlButtonWrapper">
<div class="bp-xOutButtonWrapper bp-HomeActionsButton">
<button type="button" class="bp-Button bp-homeActionButton bp-Button__type--ghost bp-Button__size--compact" tabindex="0">
<span class="ButtonIcon">
<svg class="bp-SvgIcon xout bp-SvgIcon__size--medium">
<svg viewBox="0 0 24 24">
<path fill-rule="evenodd" clip-rule="evenodd" d="a bunch of numbers here"/>
</svg>
</svg>
</span>
<span class="ButtonLabel">
X-Out</span>
</button>
</div>
</div>
<div class="ShareButtonCopFlyoutWrapper HomeControlButtonWrapper">
<div class="bp-shareButtonWrapper bp-HomeActionsButton" data-rf-test-name="abp-shareButton">
<button type="button" class="bp-Button bp-homeActionButton bp-Button__type--ghost bp-Button__size--compact" tabindex="0">
<span class="ButtonIcon">
<svg class="bp-SvgIcon share bp-SvgIcon__size--medium">
<svg viewBox="0 0 25 24">
<path fill-rule="evenodd" clip-rule="evenodd" d="a bunch of numbers here"/>
</svg>
</svg>
</span>
<span class="ButtonLabel">
Share</span>
</button>
</div>
</div>
</div>
</div>
</div>

Solution

  • Here is one tested way to click on the Favourite button:

    ## [..] your imports
    from selenium.webdriver.support.ui import WebDriverWait
    ## [..] define your driver, then
    
    wait = WebDriverWait(driver, 5)
    url = 'https://www.redfin.com/TX/Roanoke/61-Cortes-Dr-76262/home/169577463'
    driver.get(url)
    
    wait.until(EC.element_to_be_clickable((By.XPATH, '//button[@aria-label="Favorite this home"]'))).click()
    print('clicked favourite')
    

    It will print the corresponding message in the terminal, and upon click, a new overlay will be displayed, with Favorite this home title -- at least if you're not logged into the website, which I am not.

    Lastly, see Selenium documentation here.