Python Selenium无法与弹出窗口进行交互

问题描述 投票:1回答:1

首先,我想特别是对python和selenium来说,我还是一个新手。我和一位同事正在尝试使Web应用程序自动化以为我们分类付款。一切都会进行到弹出窗口出现的部分。This pop up基本上是信用卡形式。

The Issue是:您只能与字段,两个按钮交互,并且可以使用“ X”将其关闭。您无法使用开发人员工具进行检查,而我无法为此下载任何其他程序,因为工作计算机。

到目前为止,我发现的是您在地址栏中看到的链接,并且我能够使用开发人员工具的“网络”选项卡进行检查。

这里是窗口中的代码:

  <html>
  <head>
  <title> ÷ìéèú ôøèé àùøàé </title>
  </head>
  <body>
  <BR>
  <iframe id="iFrame" width="100%" height="100%" src="" frameborder="0" ></iframe> 
   <script Language="JavaScript">
  if (typeof(window.dialogArguments)!="undefined") document.getElementById('iFrame').src = window.dialogArguments;
  </script>
  </body>
  </html>

以下是位于页面本身(输入字段等)中的代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="-1">
<script src="merchantPages/WebSources/js/HE.js"></script>
<script src="merchantPages/leaseacar/js/main.js"></script>
<script src="merchantPages/leaseacar/js/tafnitTrack2.js"></script>
<link href="merchantPages/WebSources/css/main.rtl.css" rel="stylesheet" type="text/css" />

<title>דף תשלום מאובטח</title>
</head>
<body onload="resetForm();">



<!--  DISPLAY TRANSACTION INFORMATION -->
<div id="main_frame" align="center">
<div id="main">
    <div id="page_title"><img id="ssl_logo" src="merchantPages/WebSources/images/ssl.png" alt="" title=""/><h1>דף תשלום מאובטח</h1></div>
    <div id="logo"><img src="merchantPages/leaseacar/images/eTafnit.gif" alt="" title="" width="87" height="118"/></div>
    <div class="sep"></div>
    <div id="page_desc">
        <em>עמוד זה הינו עמוד התשלום עבור העסקה שביצעת באתר.<br />תשלום בעבור ההזמנה יבוצע רק לאחר בחירה בכפתור "שליחה" שבתחתית המסך.<br />אנא אשר תחילה כי כל הפרטים בדף זה נכונים והזן את פרטי כרטיס האשראי כנדרש.</em>
    </div>
    <form id="creditForm" onsubmit="return formValidator(10);" method="POST" action="ProcessCreditCard">
    <input type="hidden" name="txId" value="0ce8b10c&#45;2550&#45;4293&#45;ac6b&#45;fee0b61c5b80"/>
    <input type="hidden" name="lang" value="HE"/>
    <input type="hidden" name="last4d" value="" autocomplete="off" />
    <input type="hidden" name="cavv" value="" autocomplete="off" />
    <input type="hidden" name="eci" value="" autocomplete="off" />
    <input type="hidden" name="transactionCode" value="Phone" autocomplete="off" />
    <input type="hidden" name="expMonth" value="10" autocomplete="off" />
    <input type="hidden" name="expYear" value="24" autocomplete="off" />
    <input type="hidden" name="personalId" value="" autocomplete="off" />
    <input type="hidden" name="userData1" value=""/>
    <input type="hidden" name="userData2" value=""/>
    <input type="hidden" name="userData3" value=""/>
    <input type="hidden" name="userData4" value=""/>
    <input type="hidden" name="userData5" value=""/>
    <input type="hidden" name="userData6" value=""/>
    <input type="hidden" name="userData7" value=""/>
    <input type="hidden" name="userData8" value=""/>
    <input type="hidden" name="userData9" value=""/>
    <input type="hidden" name="userData10" value=""/>

    <table class="data_tbl">
        <thead>
            <td colspan="4" class="td_style_1">הזנת פרטי כרטיס אשראי לתשלום</td>
        </thead>
        <tr>
            <td class="td_style_fieldName">Card Number:</td>
            <td><input type="text" id="cardNumber" name="cardNumber" maxlength="19" 
style="width: 160px;" autocomplete="off" onchange="validateCardNumber();"/></td>
            <td class="td_style_invalidField" id="invalidCardNumber">&nbsp;</td>
        </tr>
        <tr>
            <td class="td_style_fieldName">CVV:</td>
            <td><input type="text" name="cvv" id="cvv" maxlength="4" style="width: 50px;" autocomplete="off" onchange="validateCvv();"/>  <img src="merchantPages/WebSources/images/qm.png"  onmouseover="showHideCVVhelp();" onmouseout="showHideCVVhelp();" style="cursor:pointer;"/><div id="CVVhelp" style="display: none; position: absolute; border: 1px #cccccc solid; padding: 10px; background: white;"><img src="merchantPages/WebSources/images/cvv.jpg" /></div></td>
            <td class="td_style_invalidField" id="invalidCvv">&nbsp;</td>
        </tr>
        <tr>
            <td class="td_style_fieldName">Track2:</td>
            <td><input type="password" name="track2" id="track2" value="" autocomplete="off" onchange="tafnitValidateTrack2();"/></td>
            <td class="td_style_invalidField" id="invalidTrack2">&nbsp;</td>
        </tr>
    </table>
    <div id="form_buttons"><input type="submit" id="submitBtn" value="שליחה" /> | <input id="resetBtn" type="reset" value="ניקוי" /></div>
    </form>
</div>
<br />
<img src="merchantPages/WebSources/images/rapidssl.gif" alt="" title=""/>
</div>
</body>

</html>

如果有人可以给我一些有关如何对准窗户的建议,以便我可以关闭,或者甚至可以关闭。

这是我到目前为止所得到的:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
#IMPORTS!-------------------------------------

usr = "***"
pwd = "***"
#app.
driver = webdriver.Ie(executable_path='C:/Users/natbag/Desktop/proj/IEDriverServer.exe')
driver.get('http://111.10.10.10/MENU1/LOGIN7.CSP')
driver.implicitly_wait(10)
username_box = driver.find_element_by_id('Username')
username_box.clear()
username_box.send_keys(usr)

password_box = driver.find_element_by_id('Password')
password_box.send_keys(pwd)

login_btn = driver.find_element_by_xpath('//input[@type="submit"]').click()

#------------------------End of Login ------------------------------------

#update contract page ----------
upd_con = driver.find_element_by_partial_link_text('עדכון חוזה').click()
#input latest Contract (F7) ----
input_con = driver.find_element_by_id('HOZ').send_keys(Keys.F7)
#goto receipts --------
receipts_btn = driver.find_element_by_xpath('//input[@name="BKBL"]').click()
Alert(driver).accept()
#input employee name ----- F7 for now later can be changed for custom number -----
work_name = driver.find_element_by_xpath('//input[@name="OVED"]').send_keys(Keys.F7)
#Receipts after username --------------------
receipts_btkn = driver.find_element_by_xpath('//input[@name="BTKBL"]').click()
#2 Seconds SLEEP IS MANDATORY!!! ----
#select Credit Card by Last Value (F7) can be changed to custom value
cc = driver.find_element_by_id('KSM').send_keys(Keys.F7)
#-------------- CANT INTERACT WITH CC WINDOW -----------------
WebDriverWait(driver, 5).until(EC.frame_to_be_available_and_switch_to_it((driver.find_element_by_xpath('//iframe[@id"iFrame"]'))))
#WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@type='text'] and [@id='cvv']"))).click()

很长的帖子,对不起,

预先感谢

python selenium popup credit-card
1个回答
0
投票

我用pyautogui弄清楚了。

tnx大家

© www.soinside.com 2019 - 2024. All rights reserved.