seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
4.46k stars 910 forks source link

Having issues detecting element #2898

Closed sirEgghead closed 5 days ago

sirEgghead commented 5 days ago
<form id="mbhVoteSubmission" method="post" action="">
<input type="hidden" name="pgstate" value="sub">
<input type="hidden" name="HDetail_ID" id="HDetail_00" value="seh">
<div class="cf-turnstile-container">
<div id="cf-turnstile2" class="cf-turnstile" data-sitekey="0x4AAAAAAAb1EYqJ3o_dxtfk" data-callback="onTurnstileSuccess" data-theme="light"><iframe src="https://challenges.cloudflare.com/cdn-cgi/challenge-platform/h/g/turnstile/if/ov2/av0/rcv0/0/murt9/0x4AAAAAAAb1EYqJ3o_dxtfk/light/normal" allow="cross-origin-isolated; fullscreen; autoplay" sandbox="allow-same-origin allow-scripts allow-popups" id="cf-chl-widget-murt9" tabindex="0" title="Widget containing a Cloudflare security challenge" style="border: none; overflow: hidden; width: 300px; height: 65px;"></iframe><input type="hidden" name="cf-turnstile-response" id="cf-chl-widget-murt9_response" value="0.vYufvwHJz1MnU3SUzr8r9qVvVK-6KXWjY2gC24d73F1IA4X6hPrXroFoKbW700rBQEhszUIQBX09yY8qQxKPbWfOJoBtWeDsC1ZvYe0a-ekLTuR2-UDUuiwulvUyE1gYOrqNltPRw817jlp3fyNk16OnlDSO4kkGW_Sw-GKyG5FyhsoHB2D9OEWX8W7VFyhk0KZzJwEO6px8gwFNGnegtnlcSNopDTDTy51wKAxqrHUrnwCzEo9IUNjkRmB4FhpLOG-SM18F86O8xXj_sdvWtNuNKiywnkiKcXeCGD4inWRjWqCuLO0Qr-qWQZK2BnCVhaaewX_vgVpndGCGKIRg1r76F-083TTjQ6SHRMdYTGYf5CU4O7gKLhUfDAOFWXdxhtLOmC3d57RYe0EQh6ueYhns4UGqmHtKdcspLjXNT7d8qtmvn8RWhDZFE8V7kxTY.VqwINBEb5l3d-LZcr1ZcNA.2644eb7f0192202bced346e28d7b95b14b1d1e7fc22b8caf3707666b9e82b594"></div>
</div>
<div class="pmessage-loader-wrap">
<p class="message-please-wait-verify">Browser security verified.</p>
</div> 
<div class="grecaptcha-button-error-top">
</div>
<input type="submit" data-test-name="Submit Vote" value="Submit Vote" name="submit_vote" class="btn btn-default btn-auto-size btn-sbmtVote btn-sbmtVote-top g-recaptcha" id="recaptcha">
</form>

The element that I'm trying to click/highlight is the "SUBMIT VOTE" input. CF passes without issue.

image

from seleniumbase import SB
import time

with SB(uc=True, demo=True) as sb:
    url = 'https://www.example.com/vote_example/'
    sb.uc_open_with_reconnect(url, reconnect_time=2)
    sb.uc_gui_handle_cf()
    sb.highlight('input:contains("submit")')
    # time.sleep(5)
    # sb.click('input:contains("Submit Vote")')
    # sb.highlight("#btn-sbmtVote")
    sb.post_message("SeleniumBase wasn't detected", duration=3)
    time.sleep(5)

I've tried a few different ways of locating the element, as seen by the commented lines. This is my first time using SB. Trying to figure this out.

Console errors with Element {input:contains("submit")} was not present after 7 seconds!

Thanks in advance!

mdmintz commented 5 days ago

input[data-test-name="Submit Vote"] should work as the selector.

If that element is inside an iframe, you'll need to switch into the iframe first: sb.switch_to_frame(selector)

sirEgghead commented 5 days ago

@mdmintz thank you for the comment. However, I did not quite get your suggestion to resolve the issue.

I tried sb.highlight('input[data-test-name="Submit Vote]') and sb.highlight('input:[data-test-name="Submit Vote]'). I grepped the source to ensure that there is no iframe.

sirEgghead commented 5 days ago

Scratch that. I changed sb.highlight to sb.click. All good. Thanks a million @mdmintz!

mdmintz commented 5 days ago

In sb.highlight, your selectors were either missing a closing double quote, or you added a : where it shouldn't belong.

Screenshot 2024-07-02 at 1 22 47 PM
sirEgghead commented 5 days ago

@mdmintz /facepalm. No excuse. Thank you <3

sirEgghead commented 5 days ago

Thumbs up on your YouTube, by the way!