Selenium:如何点击弹出窗口上的登录按钮?

时间:2015-08-18 14:00:12

标签: java flex selenium selenium-rc popupwindow

Login popup

上面的图片是弹出的弹出窗口。我使用 FlashFireBug https://addons.mozilla.org/en-us/firefox/addon/flashfirebug/)识别flash对象,如下所示(让他们的对象id在selenium中使用): enter image description here

我可以使用FlexUISelenium(https://code.google.com/p/flex-ui-selenium/)在相应的textareas中成功输入我的用户名和密码。

我编写了以下用于在textareas中输入值的代码:

@SuppressWarnings("deprecation")
public class FlexUISeleniumTestTPF {
        private final static String BASE_URL = "http://localhost:8080/FlexDemo/TTDSWeb/TTDSWeb.html";
        private final static String PAGE = "http://localhost:8080/FlexDemo/TTDSWeb/TTDSWeb.html";
        private Selenium selenium;
        private FlexUISelenium flexUITester;


        public void setUp() throws Exception {
                selenium = new DefaultSelenium("localhost", 4444, "*iexplore",BASE_URL);
                selenium.start();
                selenium.open(PAGE);
                selenium.windowMaximize();
                flexUITester = new FlexUISelenium(selenium, "TTDSWeb");
        }


        public void tearDown() throws Exception {
                selenium.stop();
        }
        public void clickLogin() throws InterruptedException{
            flexUITester.click("loginbut"); // This button opens popup
            Thread.sleep(10000);
            //Entering username
            flexUITester.type("sg0222186").at("unamelogin");
            //Entering password
            flexUITester.type("wag9hebbal").at("pwd");
        }


public static void main(String[] args) throws Exception {
    FlexUISeleniumTestTPF myTest = new FlexUISeleniumTestTPF();
    myTest.setUp();
    myTest.clickLogin();
}

现在,我想点击"登录"按钮。我认为一个想法是模拟" TAB"来自textareas的按键将重点放在按钮上,但这对我来说不起作用。请帮忙。

2 个答案:

答案 0 :(得分:0)

如果您无法点击“登录”按钮。成功输入UserID和Password的值后,请尝试发送ENTER。

即.sendKeys(Keys.ENTER)

答案 1 :(得分:0)

最后,我能够点击弹出窗口内的按钮。通过在Java中使用鼠标位置https://chrome.google.com/webstore/detail/mouse-position/mlicednebhhgebkhhmomongffeidkdmi)和 Robot 类,可以实现这一点。以下是我的代码:

{{1}}
相关问题