</head>
<body>
<div class="">
<div class="base-wrapper ">

<div class="base-main">
<div role="main" class="base-body">

<form action="/frame/prompt" method="post" id="login-form" class="inline login-form hidden">
<input type="hidden" name="sid" value="ZjUwNzUzYjA4MjVkNDc4OGJkODUyZThjOTVhMzM3ZTA&#x3d;&#x7c;70.181.192.163&#x7c;1610702974&#x7c;3040365d5035c5288c02b1c5abd3bb6bae523af0">
<input type="hidden" name="url" value="/frame/prompt">
<input type="hidden" name="enrollment_message" value="">
<input type="hidden" name="itype" value="adfs">

<input type="hidden" name="ukey" value="DUOF1NY48TBKCWXBRTRF">

<input type="hidden" name="out_of_date" value="">
<input type="hidden" name="days_out_of_date" value="">
<input type="hidden" name="should_update_dm" value="">


<input type="hidden" name="preferred_factor" value="">
<input type="hidden" name="preferred_device" value="">

<input type="hidden" name="days_to_block" value="None">
<input type="hidden" name="should_retry_u2f_timeouts" value="False">

<input type="hidden" id="has_phone_that_requires_compliance_text" name="has_phone_that_requires_compliance_text" value="False">

<fieldset class="device-selector hidden">
<h1 class="cramped-frame-view">
Device&#x3a;
</h1>
<div class="device-select-wrapper">
<select name="device" aria-label="Device" tabindex=2>





<option value="phone1">iOS &#x28;XXX-XXX-5065&#x29;</option>


</select>

</div>
</fieldset>

<div id="auth_methods">

<fieldset data-device-index="phone1" class="hidden">
<h2 class="medium-or-larger auth-method-header">
Choose an authentication method
</h2>


<div class="row-label push-label">
<input type="hidden" name="factor" value="Duo&#x20;Push">
<span class="label factor-label">
<i class="icon-smartphone-check"></i>
Duo Push


<small class="recommended">
Recommended
</small>


</span>
<button type="submit" class="auth-button&#x20;positive" tabindex="2" ><!-- -->Send Me a Push </button>
</div>




<div class="passcode-label row-label">
<input type="hidden" name="factor" value="Passcode">
<span class="label factor-label">
<i class="icon-smartphone-ellipsis" alt="" role="presentation"></i>
Passcode
</span>
<div class="passcode-input-wrapper">
<input type="text" name="passcode" autocomplete="off" data-index="phone1" class="hidden passcode-input" placeholder="ex.&#x20;867539" aria-label="passcode" tabindex=2>
<div class="next-passcode-msg" role="alert" aria-live="polite"></div>
</div>
<button type="submit" class="auth-button&#x20;positive" id="passcode" tabindex="2" ><!-- -->Enter a Passcode </button>
<input name="phone-smsable" type="hidden" value="False" />
<input name="mobile-otpable" type="hidden" value="True" />
<input name="next-passcode" type="hidden" value="None" />
</div>

</fieldset>





<input type="hidden" name="has-token" value="false">


</div>

<div>

</div>
</form>


</div>
</div>
<div class="base-navigation">

<div class="base-navigation">
<div role="banner">

<a href="&#x2f;frame&#x2f;prompt&#x3f;sid&#x3d;ZjUwNzUzYjA4MjVkNDc4OGJkODUyZThjOTVhMzM3ZTA&#x3d;&#x7c;70.181.192.163&#x7c;1610702974&#x7c;3040365d5035c5288c02b1c5abd3bb6bae523af0">
<img src="&#x2f;frame&#x2f;logo&#x3f;sid&#x3d;ZjUwNzUzYjA4MjVkNDc4OGJkODUyZThjOTVhMzM3ZTA&#x3d;&#x7c;70.181.192.163&#x7c;1610702974&#x7c;3040365d5035c5288c02b1c5abd3bb6bae523af0" alt="CSUSM&#x20;Authentication" width="128"/>
</a>

</div>
<div class="help-sidebar">
<button class='btn btn-support'>
<i class="icon-align-justify" aria-label="Open"></i>
<i class="icon-delete" aria-label="Close"></i>
Settings
</button>
<div class="help-links">
<nav role="navigation">

<a id="help_link" class="help-nav" href="https&#x3a;&#x2f;&#x2f;guide.duo.com&#x2f;prompt" target="_blank" aria-label="What&#x20;is&#x20;the&#x20;Duo&#x20;Prompt&#x3f;&#x20;&#x28;Opens&#x20;in&#x20;a&#x20;new&#x20;tab.&#x29;">
What is this&#x3f;<i class="icon-new-window"></i>
</a>


<a class="help-nav" id="new-device" href="/frame/enroll/pre_flow_prompt?sid=ZjUwNzUzYjA4MjVkNDc4OGJkODUyZThjOTVhMzM3ZTA%3D%7C70.181.192.163%7C1610702974%7C3040365d5035c5288c02b1c5abd3bb6bae523af0&post_auth_action=addDevice">
Add a new device
</a>
<a class="help-nav" href="/frame/enroll/pre_flow_prompt?sid=ZjUwNzUzYjA4MjVkNDc4OGJkODUyZThjOTVhMzM3ZTA%3D%7C70.181.192.163%7C1610702974%7C3040365d5035c5288c02b1c5abd3bb6bae523af0&post_auth_action=manageDevices">
My Settings &amp; Devices
</a>

<a href="#" class="need-help">Need help&#x3f;</a>
</nav>

<div role="contentinfo">
<a href="https&#x3a;&#x2f;&#x2f;duo.com" class="branding-link" target="_blank">
Powered by Duo Security
</a>
</div>


</div>

</div>
<div class="help-overlay offscreen">
<div class="help-links">
<nav role="navigation">

<a id="help_link" class="help-nav" href="https&#x3a;&#x2f;&#x2f;guide.duo.com&#x2f;prompt" target="_blank" aria-label="What&#x20;is&#x20;the&#x20;Duo&#x20;Prompt&#x3f;&#x20;&#x28;Opens&#x20;in&#x20;a&#x20;new&#x20;tab.&#x29;">
What is this&#x3f;<i class="icon-new-window"></i>
</a>


<a class="help-nav" id="new-device" href="/frame/enroll/pre_flow_prompt?sid=ZjUwNzUzYjA4MjVkNDc4OGJkODUyZThjOTVhMzM3ZTA%3D%7C70.181.192.163%7C1610702974%7C3040365d5035c5288c02b1c5abd3bb6bae523af0&post_auth_action=addDevice">
Add a new device
</a>
<a class="help-nav" href="/frame/enroll/pre_flow_prompt?sid=ZjUwNzUzYjA4MjVkNDc4OGJkODUyZThjOTVhMzM3ZTA%3D%7C70.181.192.163%7C1610702974%7C3040365d5035c5288c02b1c5abd3bb6bae523af0&post_auth_action=manageDevices">
My Settings &amp; Devices
</a>

<a href="#" class="need-help">Need help&#x3f;</a>
</nav>

<div role="contentinfo">
<a href="https&#x3a;&#x2f;&#x2f;duo.com" class="branding-link" target="_blank">
Powered by Duo Security
</a>
</div>


</div>

</div>
</div>

</div>
<div class="base-sidebar">

</div>
<div id="messages-view" class="hidden">
<div class="messages-list">

</div>
</div>


</div>
</div>
<script id="translations" type="text/json">
{"domain": "js-messages", "locale_data": {"js-messages": {"": {"domain": "js-messages", "plural_forms": "nplurals&#x3d;2&#x3b; plural&#x3d;&#x28;n &#x21;&#x3d; 1&#x29;&#x3b;", "lang": "en"}}}}
</script>


<script src="&#x2f;frame&#x2f;static&#x2f;shared&#x2f;lib&#x2f;jquery&#x2f;jquery-prologue.js&#x3f;v&#x3d;400dc"></script>
<script src="&#x2f;frame&#x2f;static&#x2f;shared&#x2f;lib&#x2f;jquery&#x2f;jquery-legacy.min.js&#x3f;v&#x3d;72e7b"></script>
<script src="&#x2f;frame&#x2f;static&#x2f;shared&#x2f;lib&#x2f;he&#x2f;he.min.js&#x3f;v&#x3d;aaa33"></script>
<script src="&#x2f;frame&#x2f;static&#x2f;js&#x2f;lib&#x2f;jquery-postmessage.min.js&#x3f;v&#x3d;98c73"></script>
<script src="&#x2f;frame&#x2f;static&#x2f;shared&#x2f;lib&#x2f;lodash&#x2f;lodash.min.js&#x3f;v&#x3d;14516"></script>
<script src="&#x2f;frame&#x2f;static&#x2f;shared&#x2f;lib&#x2f;backbone&#x2f;backbone-min.js&#x3f;v&#x3d;28a93"></script>
<script src="&#x2f;frame&#x2f;static&#x2f;js&#x2f;page&#x2f;v3&#x2f;frame.js&#x3f;v&#x3d;82022"></script>
<script src="&#x2f;frame&#x2f;static&#x2f;js&#x2f;page&#x2f;v3&#x2f;base.js&#x3f;v&#x3d;d6293"></script>
<script src="&#x2f;frame&#x2f;static&#x2f;shared&#x2f;lib&#x2f;validator&#x2f;validator.min.js&#x3f;v&#x3d;9a068"></script>
<script src="&#x2f;frame&#x2f;static&#x2f;shared&#x2f;lib&#x2f;jquery&#x2f;jquery-epilogue.js&#x3f;v&#x3d;c4ac5"></script>
<script id="browser_exceptions" src="&#x2f;frame&#x2f;static&#x2f;shared&#x2f;js&#x2f;errors.js&#x3f;v&#x3d;96827" data-url="/frame/browser_exceptions"></script>
<input type="hidden" name="helpdesk-message" id="helpdesk-message" value="Please&#x20;visit&#x20;https&#x3a;&#x2f;&#x2f;www.csusm.edu&#x2f;iits&#x2f;iitsforyou&#x2f;multifactor-authentication&#x2f;index.html&#x20;for&#x20;videos&#x20;and&#x20;guides&#x20;for&#x20;faculty,&#x20;staff,&#x20;and&#x20;students." />
<!--[if lt IE 10]>
<script src="&#x2f;frame&#x2f;static&#x2f;js&#x2f;page&#x2f;v3&#x2f;quirks.js&#x3f;v&#x3d;1ed89"></script>
<!--<![endif]-->


<script src="&#x2f;frame&#x2f;static&#x2f;js&#x2f;lib&#x2f;jquery.tipsy.js&#x3f;v&#x3d;c0432"></script>
<script src="&#x2f;frame&#x2f;static&#x2f;js&#x2f;page&#x2f;v3&#x2f;prompt.js&#x3f;v&#x3d;3f751"></script>


<!--[if lt IE 9]>
<script src="&#x2f;frame&#x2f;static&#x2f;js&#x2f;lib&#x2f;html5shiv.js&#x3f;v&#x3d;86fbf"></script>
<![endif]-->
</body>
</html>

Saya mencoba mengklik tombol di telepon

<button type="submit" class="auth-button&#x20;positive" tabindex="2" ><!-- -->Send Me a Push </button>

Apa yang saya coba sejauh ini:

iframe = driver.find_element_by_xpath("//iframe[@id='duo_iframe']")

driver.switch_to.frame(iframe)

Maka berikut ini

driver.find_element_by_css_selector(".row-label").click()

Atau

driver.find_element_by_xpath("//div[@class='row-labeldiv.row-label:nth-child(2)']/button[.='Send Me a Push']").click()

Atau

driver.find_element_by_xpath("//button[text()='Send Me a Push']").click()

Tidak peduli apa yang saya coba, selenium tidak dapat menemukan elemen tersebut. Saya tidak yakin apa yang saya lewatkan. Saya tahu tombol yang saya coba klik tidak memiliki kelas yang unik. Solusi paling jelas yang saya temukan di stackoverflow adalah menggunakan teks di dalam tombol untuk mengkliknya, namun bahkan setelah beralih ke iframe yang benar (?), Saya masih tidak dapat menemukan elemennya.

Saya berasumsi saya beralih ke iframe yang diberikan dengan benar setelah memeriksa elemen di chrome dan menemukan

<iframe id="duo_iframe" src="https://api-b22f1fa2.duosecurity.com/frame/web/v1/auth?tx=TX|Y3N1c21cY2Fub24wMTB8RElBWlU2VzJCOUFRTExEQ1pCWDZ8MTYxMDcwMzI0MA==|883b56e2b24048e526a973c70d5bdb359db905d1&amp;parent=https%3A%2F%2Fauth.csusm.edu%2Fadfs%2Fls%2F%3FSAMLRequest%3DnZJBTwIxEIX%252Fyqb3pbtdINAACUqMJKhE0IMXM3QHabJt105r9N%252B77GpEDxw8NZ2Z7%252BXNy0wITFXLeQwHe4%252BvESkk76ayJNvGlEVvpQPSJC0YJBmU3MxvVlL0Mll7F5xyFTtBzhNAhD5oZ1myXEzZ804MxkIVGYwFCiXyYTYY9%252FvjkdrtixyGxWgIOOoXwzxjySN6asgpa4QanCji0lIAG5pSJvI0y9N8sM0KKYTM8ieWLJpttIXQUocQapKcQ7NqT1Ek08Mycij3xCviLJl%252Fe7t0lqJBv0H%252FphU%252B3K9%252BaKVOWNKmrvC4NTeujBX26kPN2z91r0hBUVstcQ%252BxCinVLFl%252F5Xahbanty%252FnIdt0Qyevtdp2u7zZbNpsctWUbgZ%252F9w5rBACUE%252BONswk91J91p3DaOlou1q7T6SK6cNxDOGz5WdJnu21EZPFjSaAPjs07%252F97XNPgE%253D%26RelayState%3Dhttps%253A%252F%252Fcc.csusm.edu%252Fauth%252Fsaml%252Findex.php%26SigAlg%3Dhttp%253A%252F%252Fwww.w3.org%252F2001%252F04%252Fxmldsig-more%2523rsa-sha256%26Signature%3DWAdtwVP3PFqkG5AOq0gspZJPT06j6VOrKiK1p3RqsMWqug7xj4NZaHLf4ZAkhLoFdw0kIsV7EAWxi1KHRGi0AvUGoyue5EeEo6TqEuzHDBLOITdLR0xIvCjbmlXT0KfAsX1f2Vrm0tn4FPH7VETu%252BpjKQDM15TwPkfdGAWs5Eqr2ZzA9GDI5Lwg9GNakWpBqNvhC0gQ5gDiPKxigGvyLw1V5xFSOQqn4Xx5uUDvSUezAFPxB6yq72a5e0NzTmc%252FVRRliiqAjH4xMRagTgdOOruXIwBPBFlUmzy8ySChKAGjAOuXgq8uz0vEjDuYcSd%252F7A0IrBrN5GLVVrqTiqKxoSA%253D%253D&amp;v=2.6" frameborder="0"></iframe>

Merangkum tombol yang saya coba tekan dan Selenium menemukan dan beralih juga.

1
JyCan12 15 Januari 2021, 12:37

3 jawaban

Jawaban Terbaik

Untuk mengklik elemen dengan teks sebagai Send Me a Push Anda dapat menggunakan salah satu dari Strategi Pencari Lokasi:

  • Menggunakan css_selector:

    driver.find_element(By.CSS_SELECTOR, "button[class^='auth-button'][type='submit']").click()
    
  • Menggunakan xpath:

    driver.find_element(By.XPATH, "//button[starts-with(@class, 'auth-button') and contains(., 'Send Me a Push')]").click()
    

Idealnya, untuk mengklik elemen yang Anda butuhkan untuk menginduksi WebDriverTunggu untuk element_to_be_clickable() dan Anda dapat menggunakan salah satu dari Strategi Pencari Lokasi:

  • Menggunakan CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[class^='auth-button'][type='submit']"))).click()
    
  • Menggunakan XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[starts-with(@class, 'auth-button') and contains(., 'Send Me a Push')]"))).click()
    
  • Catatan: Anda harus menambahkan impor berikut :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
0
DebanjanB 15 Januari 2021, 10:39

Gunakan:

driver.find_element_by_xpath("//button[contains(text(),'Send Me a Push')"]).click()

Tidak ada iframe di html yang Anda tambahkan dalam pertanyaan, jika html yang ditambahkan adalah konten di dalam iframe maka beralihlah ke iframe dan kemudian gunakan pencari yang disebutkan

1
PDHide 15 Januari 2021, 10:44

Saya pikir iframe mungkin memiliki # di urlnya seperti ini: www.someurl.com/page/#/something, coba hapus #: www.someurl.com/page/something.

-1
Leemosh 15 Januari 2021, 09:39