java - 需要帮助来点击一个函数

标签 java selenium dialog

我想单击一个工具提示大小的小对话框,其中包含“删除关联”内容。我有以下脚本:

strMenu_Body = menu.document.body;
    strMenu_Body.style.backgroundColor = "#EFF6FD";
    var strMenu_Text = "<TABLE Align=Center width=100% height=100% CellPadding=0 CellSpacing=0 Border=1 BorderColor=#A5BACE style=font-family:arial;font-size:12px;color:black;>"
    if (type != "Flag") {
        if (val.indexOf('s10001') > 0) {
            if (document.all(val).iComponentType) {
                if (document.all(val).iComponentType == "Recall")
                    strMenu_Text = strMenu_Text + "<TR HEIGHT=20 ID=traSch1 ><TD align=center>&nbsp;<Font ID=RemoveAssociation onClick=parent.callParent('" + val + "','DELETE_ASSOCIATION') style=cursor:hand onmouseover=javascript:this.style.color='red'; onmouseout=javascript:this.style.color='black';>Delete Recall</Font></TD></TR>"
                else
                    strMenu_Text = strMenu_Text + "<TR HEIGHT=20 ID=traSch1 ><TD align=center>&nbsp;<Font ID=RemoveAssociation onClick=parent.callParent('" + val + "','DELETE_ASSOCIATION') style=cursor:hand onmouseover=javascript:this.style.color='red'; onmouseout=javascript:this.style.color='black';>Cancel Appointment</Font></TD></TR>"
            }
            else
                strMenu_Text = strMenu_Text + "<TR HEIGHT=20 ID=traSch1 ><TD align=center>&nbsp;<Font ID=RemoveAssociation onClick=parent.callParent('" + val + "','DELETE_ASSOCIATION') style=cursor:hand onmouseover=javascript:this.style.color='red'; onmouseout=javascript:this.style.color='black';>Delete Recall</Font></TD></TR>";
        }
        else if (val.indexOf('s20002') > 0) {
            if (document.all("btn~~PatEducations20002").all("Comp_Heading").innerHTML.length > 20)
                strMenu_Text = strMenu_Text + "<TR HEIGHT=20 ID=traSch1 ><TD>&nbsp;<Font ID=RemoveAssociation onClick=parent.removePatientEducation(0); style=cursor:hand onmouseover=javascript:this.style.color='red'; onmouseout=javascript:this.style.color='black';>Remove Flag</Font></TD></TR>"
            else
                strMenu_Text = strMenu_Text + "<TR HEIGHT=20 ID=traSch1 ><TD align=center>&nbsp;<Font ID=RemoveAssociation onClick=parent.removePatientEducation(1); style=cursor:hand onmouseover=javascript:this.style.color='red'; onmouseout=javascript:this.style.color='black';>Remove Association</Font></TD></TR>"
        }
        else
            strMenu_Text = strMenu_Text + "<TR HEIGHT=20 ID=traSch1 ><TD>&nbsp;<Font ID=RemoveAssociation onClick=parent.callParent('" + val + "','DELETE_ASSOCIATION') style=cursor:hand onmouseover=javascript:this.style.color='red'; onmouseout=javascript:this.style.color='black';>Remove Association</Font></TD></TR>"
    }
    else
        strMenu_Text = strMenu_Text + "<TR HEIGHT=20 ID=traSch1 ><TD>&nbsp;<Font ID=RemoveAssociation onClick=parent.callParent('" + val + "','DELETE_FLAG_ASSOCIATION') style=cursor:hand onmouseover=javascript:this.style.color='red'; onmouseout=javascript:this.style.color='black';>Remove Flag</Font></TD></TR>"
        strMenu_Text = strMenu_Text + "</TABLE>"
        strMenu_Body.innerHTML = strMenu_Text
        menu.show(intMenu_X, intMenu_Y, intMenu_Width, intMenu_Height, document.all("cmbFontName"))
}

`

我不知道如何点击那个对话框。请帮助。我正在使用 java、selenium、IE 10、Win 8。

另请告诉我如何单击具有属性“onclick”的元素,例如 onClick=parent.callParent('"+ val + "','DELETE_ASSOCIATION')。非常感谢

最佳答案

你可以使用一些 javascript 注入(inject)魔法,试试这个:

WebElement element = driver.findElement(By.xpath("//*[contains(text(),'Remove Association')]"));  
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);

关于java - 需要帮助来点击一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20391544/

相关文章:

java - 线程在main方法中启动

java - Spring JPA hibernate 副本

java - Chromedriver 元素在点 (xxx, yyy) 处不可点击。其他元素将收到点击 :

jQuery mobile 和弹出对话框

jquery - 如何使 jQuery 对话框仅在单击按钮后才显示?

java - 我是否需要刷新或关闭自定义 Spring Web MessageConverter 中的 OutputStream

java - 扫描仪双值 - InputMismatchException

selenium - 如何使用 Selenium 查找包含的元素

python - 我可以在没有使用 python 打开实际浏览器的情况下将 selenium 与 Scrapy 一起使用吗

android - 如何以编程方式关闭 Android Speech To Text 对话框