Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java WebDriver无法在属性为onclick=function1()的输入元素上执行单击_Java_Webdriver_Selenium Webdriver - Fatal编程技术网

Java WebDriver无法在属性为onclick=function1()的输入元素上执行单击

Java WebDriver无法在属性为onclick=function1()的输入元素上执行单击,java,webdriver,selenium-webdriver,Java,Webdriver,Selenium Webdriver,我在Java中使用Web驱动程序2.31。web驱动程序似乎无法对具有onclick()属性的输入元素执行单击操作 我需要对其执行单击操作的输入元素具有以下属性—id(这是一个随机生成的数字)、class、type=button、onclick、onmouseout、onmouseover、title和value 我能够获取title和value属性的值,这意味着web驱动程序能够识别输入元素,但不能对其执行单击操作 我尝试了以下方法: webdriver.findElement(By.xpat

我在Java中使用Web驱动程序2.31。web驱动程序似乎无法对具有
onclick()
属性的输入元素执行单击操作

我需要对其执行单击操作的输入元素具有以下属性—
id
(这是一个随机生成的数字)、
class
type=button
onclick
onmouseout
onmouseover
title
value

我能够获取
title
value
属性的值,这意味着web驱动程序能够识别输入元素,但不能对其执行单击操作

我尝试了以下方法:

  • webdriver.findElement(By.xpath(“输入的xpath”))。单击()
  • webdriver.findElement(By.xpath(“输入的xpath”)).sendKeys(Keys.ENTER)
  • newactions(webdriver).moveToElement(webdriver.findElement(By.xpath(“输入的xpath”)))。单击().perform()

  • 以上选项都不起作用

    是否从element.click()获取任何异常?是否启用并可见?我们遇到的一个问题是WebDriver没有正确处理位置:静态元素,因此在播放过程中,它会覆盖按钮(您在屏幕截图上看不到),并且会抛出异常“元素在某一点不可单击”

    我们在元素方面也有类似的问题,并且有以下代码有时确实有效(但也不是100%有效):


    但升级WebDriver后,问题自行消失,我们删除了sendKeys(ENTER),并且在2.29.0中运行良好。

    我在项目中遇到了完全相同的问题问题在于没有找到元素,但onClick()事件没有触发。 然后我发现还有其他东西从事件开始就停止了。我使用java脚本启用了日期选择器框&这样做了

    ((JavascriptExecutor)driver).executeScript ("document.getElementById('txtOriginDate').removeAttribute('readonly',0);");
    
    WebElement originDateBox= driver.findElement(By.xpath(prop.getProperty("originDateBox")));
    originDateBox.clear();
    originDateBox.sendKeys("9-Dec-2014"); //Enter date  
    
    开发人员这样设计:若不使用日期选择器选择日期,则不会设置特定变量最终使**onclick事件不触发

    日期选择器代码是这样的

    var jsoncustdate = "";
    var jsonorigindate = "";
    
    function onSelectCalender( StrDt, obj ) 
    {
        if ( !varReadonly ) {
        if ( $( "#txtCustDescisionDate" ).attr( "IsDisable" ) == "FALSE" ) 
        {
            if ( obj.id == "txtCustDescisionDate" ) 
            {
                custobjDt = new Date( obj.selectedYear, obj.selectedMonth,obj.selectedDay, 0, 0, 0, 0 );
                jsoncustdate = custobjDt.getTime();
                jsoncustdate = "\/Date(" + jsoncustdate + ")\/";
                DisabledBtnStage();
                //        $("#txtFromDate").datepicker("option", "maxDate", objDt);
    
            }
            if ( obj.id == "txtOriginDate" ) 
            {
                var objDt = new Date( obj.selectedYear, obj.selectedMonth,obj.selectedDay,0, 0,0,0 );
                jsonorigindate = objDt.getTime();
                jsonorigindate = "\/Date(" + jsonorigindate + ")\/";
                DisabledBtnStage();
                //        $("#txtToDate").datepicker("option", "minDate", objDt);
            }
        }
        elogCommon.CheckMandatory();
      }
    
    }
    
    我终于以正常的方式使用了日期选择器&事件顺利进行


    我希望这个答案会有帮助。干杯

    发布应用程序的html代码。这是我需要执行单击操作的输入元素的html。是否可能是selenium在加载和定义
    goNext()
    之前尝试单击?此外,根据
    buttonOFf
    buttonOn
    的css属性,
    onmouseover
    onmouseout
    事件可能存在问题?根据brett语句,在单击按钮之前将鼠标放在该按钮上。驱动程序是否引发异常?是否确定该元素是要单击执行的元素?
    var jsoncustdate = "";
    var jsonorigindate = "";
    
    function onSelectCalender( StrDt, obj ) 
    {
        if ( !varReadonly ) {
        if ( $( "#txtCustDescisionDate" ).attr( "IsDisable" ) == "FALSE" ) 
        {
            if ( obj.id == "txtCustDescisionDate" ) 
            {
                custobjDt = new Date( obj.selectedYear, obj.selectedMonth,obj.selectedDay, 0, 0, 0, 0 );
                jsoncustdate = custobjDt.getTime();
                jsoncustdate = "\/Date(" + jsoncustdate + ")\/";
                DisabledBtnStage();
                //        $("#txtFromDate").datepicker("option", "maxDate", objDt);
    
            }
            if ( obj.id == "txtOriginDate" ) 
            {
                var objDt = new Date( obj.selectedYear, obj.selectedMonth,obj.selectedDay,0, 0,0,0 );
                jsonorigindate = objDt.getTime();
                jsonorigindate = "\/Date(" + jsonorigindate + ")\/";
                DisabledBtnStage();
                //        $("#txtToDate").datepicker("option", "minDate", objDt);
            }
        }
        elogCommon.CheckMandatory();
      }
    
    }