A site I'm scraping recently changed the button ID I was using. For some reason, I can't find the new element. I've read through multiple sites (including Stack Overflow) on selecting a button, nothing I try works. I'm pretty much a newbie at Selenium. Here's the HTML extract:
<div class="info">
<h4 class="store-number">
Store Number: {{=storeId}}
</h4>
{{ if (closeForEcommerce == 0 ) { }}
<button id="store-search-modal-make-this-my-store-{{=storeId}}" class="btn btn-make-this-my-store btn-block btn-primary-2 {{ if (ResultDisplayHelper.isMyStore(storeId)) { print("hidden"); } }}"
onclick="ResultDisplayHelper.setMyStoreMarker({{=storeId}});ResultDisplayHelper.setMyStore('store-search-modal-abc-store-card-info-', 'store-search-modal-make-this-my-store-', 'store-search-modal-my-store-', {{=storeId}})">
Make This My Store
</button>
{{ } }}
{{ if (closeForEcommerce != 0 ) { }}
<button id="btnStoreCloseForEcommerce" class="btn btn-store-temporarily-closed btn-block btn-primary-2 {{ if (ResultDisplayHelper.isMyStore(storeId)) { print("hidden"); } }}"
onclick="">
Store Temporarily Closed
</button>
{{ } }}
<a id="store-search-modal-my-store-{{=storeId}}" href="{{=clickUri}}" class="CoveoResultLink my-store btn btn-gray-300 btn-block {{ if (!ResultDisplayHelper.isMyStore(storeId)) { print("hidden"); } }}">
My Store
</a>
<a class="CoveoResultLink" href="{{=clickUri}}">Visit Store Page</a>
<div class="location">
{{ if (dist != null) { }}
<div><strong>Miles</strong>: {{=ResultDisplayHelper.metersToMiles(dist)}}</div>
{{ } }}
<address>
{{ if (shoppingcenter) { }}
{{=shoppingcenter}}<br/>
{{ } }}
{{=address1}}
{{ if (address2) { }}<br />{{=address2}} {{ } }}
<br />
{{=city}}, {{=state}} {{=zip}}
</address>
</div>
I've tried
button_id = 'store-search-modal-make-this-my-store-'+shop
make_my_store = driver.find_element_by_id(button_id)
and
make_my_store = driver.find_element_by_xpath("//button[contains(text(),'Make
This My Store')]")
with the results:
NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"store-search-modal-make-this-my-store-231"}
(Session info: headless chrome=67.0.3396.99)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.17134 x86_64)
and
NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"button[onclick^=ResultDisplayHelper]"}
(Session info: headless chrome=67.0.3396.99)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.17134 x86_64)
What am I missing?
UPDATE: Thanks for the suggestions so far. Unfortunately when I tried the multiple variations, I keep getting timeout errors as the object isn't found. I grabbed driver.page the source and see:
<button id="make-this-my-store" class="btn btn-block btn-primary-2"
ng-show="model.store.storeId !== model.abcCartService.cart.pickupStore.storeId &&
model.store.closeForEcommerce !== 'True'" ng-click="model.makeMyStore();">
Make This My Store
</button>
I've tried looking for "Make This My Store" using XPATH, using "make-this-my-store" as the button ID, and "btn btn-block btn-primary-2" as the CSS class. All give object not found errors.