PIN键盘问题与Selenium WebDriver

时间:2014-04-02 16:30:12

标签: java selenium selenium-webdriver automated-tests

我需要Selenium WebDriver的帮助。我试图自动化一个网站,但卡在密码键盘区域。

当我点击PIN输入元素时,该元素处于只读状态,只能通过鼠标点击PIN码接受值。请注意,只要弹出/刷新,PIN键盘上的数字位置就会改变。

编辑(补充资料):

可在www.mypaga.com网站上公布。您可以使用此ID执行某些事务,如AcceptDeposit。用户名:ibile,安全问题:4,密码:ibile4live

以下是代码:

package com.paga.testing.agent.online;

import java.util.concurrent.TimeUnit;

import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class AcceptDepositTest extends LoginTest {

    @BeforeClass
    public static void beginTest() {
        System.out.println("********* Begin *************");
        Assume.assumeTrue(loginTest());
    }

    @Test
    public void acceptDepositTest(){
        WebDriverWait wait = new WebDriverWait(driver, 5);
        wait.until(ExpectedConditions.elementToBeClickable(By.className("acceptDeposit")));
        System.out.println("acceptDepositTest Running");
        driver.findElement(By.className("acceptDeposit")).click();
        driver.findElement(By.id("amount")).click();
        driver.findElement(By.id("amount")).clear();
        driver.findElement(By.id("amount")).sendKeys("1000");
        driver.findElement(By.id("customerPhoneNumber")).clear();
        driver.findElement(By.id("customerPhoneNumber")).sendKeys("08022614279");
        driver.findElement(By.className("button_go")).click();
        System.out.println("pin pad");


     // Enter PIN
        wait.until(ExpectedConditions.elementToBeClickable(By.id("confirmPin")));
        driver.findElement(By.id("confirmPin")).click();
        System.out.println("pin pad22");
        driver.findElement(By.id("confirmPin")).sendKeys("1234");

        driver.findElement(By.className("button_go")).click();

        //driver.findElement(By.id("confirmPin")).sendKeys("1234");
        //return flag;
    }

    @AfterClass
    public static void ending(){
        System.out.println("********* End *************");
    }
}

这是PIN PAD代码。请注意,每次刷新时密码键盘值的位置都会改变

<div id="keypad-div" style="text-align: left; float: left; position: absolute; top: 431.067px; width: auto; left: 915.817px; display: block;">
    <div class="keypad-row">
        <button class="keypad-key" title="" type="button">9</button>
        <button class="keypad-key" title="" type="button">7</button>
        <button class="keypad-key" title="" type="button">2</button>
        <button class="keypad-key keypad-close" title="Close the keypad" type="button">Ok</button>
    </div>
    <div class="keypad-row">
        <button class="keypad-key" title="" type="button">4</button>
        <button class="keypad-key" title="" type="button">3</button>
        <button class="keypad-key" title="" type="button">6</button>
        <button class="keypad-key keypad-back" title="Erase the previous character" type="button">Delete</button>
    </div>
    <div class="keypad-row">
        <button class="keypad-key" title="" type="button">5</button>
        <button class="keypad-key" title="" type="button">1</button>
        <button class="keypad-key" title="" type="button">8</button>
    </div>
    <div class="keypad-row">
    <div class="keypad-space"/>
    <button class="keypad-key" title="" type="button">0</button>
</div>

1 个答案:

答案 0 :(得分:0)

对于该特定密码键盘,您是否可以发送密码,因为您已经知道元素ID?与以下示例类似:

/ *提交密码* /

 driver.findElement(By.id("pin_id")).click();
 driver.findElement(By.id("pin_id")).clear();
 driver.findElement(By.id("pin_id")).sendKeys(pinID);