java / selenium - 如何点击主页顶部弹出的表单中的元素?

时间:2015-05-11 12:08:30

标签: java selenium xpath

在我的自动化项目中的某个点上,我必须单击一个元素,该元素是弹出主页面顶部的表单的一部分(它不会像悬停时显示的那些菜单一样消失成功访问页面并单击显示表单的元素后,某个元素然后消失。

我一直在尝试从其他问题的评论中提出的各种解决方案,例如使用偏移并等待元素变为可点击,但没有一个对我有效。

这是第一个字段“Name”的当前状态代码:

private InputMethodManager mInputMethodManager;

EditText mRecordFileNameET = (EditText) findViewById(R.id.recorder_recordFileName_et);
mRecordFileNameET.setOnKeyListener(this);

@Override
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.recorder_recordFileName_tv:
        mRecordFileNameET.requestFocus();
        showSoftKeyboard(true);
        break;
    }

}

//this method is used to show and hide soft keyboard
private void showSoftKeyboard(boolean showkeyboard) {
    if (showkeyboard) {
        mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        mInputMethodManager.showSoftInput(mRecordFileNameET, InputMethodManager.SHOW_IMPLICIT);
    } else {
        mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        mInputMethodManager.hideSoftInputFromWindow(mRecordFileNameET.getWindowToken(), 0);
    }

}

编辑 - 工作代码(感谢segalaj):

try {
                System.out.println("Filling in mandatory fields of the contact form... ");
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='jcemediabox-popup-frame']")));

                System.out.println("Filling in name... ");
                wait.until(ExpectedConditions.elementToBeClickable(By.xpath("(//div[@class='formBody']/input)[1]")));
                WebElement nameField = driver.findElement(By.xpath("(//div[@class='formBody']/input)[1]"));
                actions.moveToElement(nameField).build().perform();
                actions.moveByOffset(5, 5).build().perform();
                nameField.sendKeys(contactInput[1]);
                nameField.submit();
                System.out.println("Filled in name");

            } catch (Exception e) {
                System.out.println("Could not complete actions on: contact form");
                e.printStackTrace();
            }

0 个答案:

没有答案