【问题标题】:Need help for clicking a function需要有关单击功能的帮助
【发布时间】:2013-12-05 04:39:07
【问题描述】:

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

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')。非常感谢

【问题讨论】:

  • 只要元素为Onclick属性,就可以做到driver.findElement(By.xpath("//*[contains(text(),'Remove Association')]")).click()
  • 我试过这个@Richard 但没用。无论如何,感谢您的帮助。

标签: java selenium dialog


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    如果您有元素的 id,您也可以使用它来生成点击。

    但是请记住,当您将鼠标悬停在其他一些 html 控件上时,您的工具提示就会出现。因此,您的工具提示仅在这种情况下可见,实际上 Selenium 不允许您单击隐藏元素。所以首先你必须让它可见然后点击它。

    希望对您有所帮助。不确定这是您要查找的内容。

    【讨论】:

    • 它不是工具提示,我说的是工具提示的大小。当我右键单击文本时,会出现此“删除关联”。
    • 你能不能试试 driver.findElements(By.xpath("//*[contains(.,'Remove Association')]"))。这将为您提供一个 WebElement 列表,遍历它们并查看是否找到该元素,然后您可以在 webelement 中调用 click() 函数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-05
    相关资源
    最近更新 更多