1
</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>

I'm trying to click the button on the line

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

What I have tried so far:

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

driver.switch_to.frame(iframe)

then the following

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

or

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

or

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

No matter what I try, selenium cannot find the element. I'm not sure what I'm missing. I know the button I am trying to click doesn't have a unique class. The most obvious solution I found on stackoverflow was using the text inside the button to click it, however even after switching to the correct iframe(?), I still cannot find the element.

I assume I switched to the iframe correctly given after inspecting element on chrome and finding

<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>

encapsulating the buttons I'm trying to press and selenium finding and switching too it.

JyCan12
  • 43
  • 5

4 Answers4

1

use :

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

there is no iframe in the html you added in the question , if the html added was the content inside iframe then switch to iframe and then use the mentioned locator

PDHide
  • 18,113
  • 2
  • 31
  • 46
  • Thanks for the help! I edited the post to explain where I found the iframe I believe I'm supposed to switch too. Unfortunately, your solution did not work..any ideas? – JyCan12 Jan 15 '21 at 18:33
0

To click on the element with text as Send Me a Push you can use either of the following Locator Strategies:

  • Using css_selector:

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

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

Ideally, to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[class^='auth-button'][type='submit']"))).click()
    
  • Using 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()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Your Xpath wait solution worked! Thank you so much. I guess I was stubborn in thinking that I didn't have to induce a wait seeing as the page itself is small and selenium would be able to see everything. – JyCan12 Jan 15 '21 at 18:46
0

I tried below code and it worked:

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='duo_iframe']")));
Thread.sleep(3000);
driver.findElement(By.xpath("//div[@id='auth_methods']/fieldset/div[1]/button")).click();
Selnay
  • 699
  • 4
  • 16
sp27
  • 1
-1

I think iframes might have a # in their url like this: www.someurl.com/page/#/something, try removing the #: www.someurl.com/page/something.

Leemosh
  • 883
  • 6
  • 19
  • I wonder why did I get downvote, when I came across this problem a while ago and this was the solution. – Leemosh Jan 15 '21 at 10:20
  • I didn't down vote , but what you mean by iframe has url ? You mean the src attribute ? Why would you modify an element from script ? . That's not a right solution – PDHide Jan 15 '21 at 10:42
  • I may have not said it in the right way. You are accessing an url and that url might have a `#` inside and if you remove that `#` then you might be able to access the iframes. I encountered this once. – Leemosh Jan 15 '21 at 11:09