Need help for clicking a function

Viewed 85

I want to click a small tool tip sized dialoge box that has the content "Remove Association" in it. I have the following scripts for it:

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"))
}

`

I dont know how to click that dialoge box. kindly help. I am using java, selenium, IE 10, Win 8.

Also please tell me how to click elements with attribute "onclick" e.g onClick=parent.callParent('" + val + "','DELETE_ASSOCIATION'). Many thanks

2 Answers

You can use some javascript inject magic, try this:

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

I you have an id of the element you can also use that to generate a click.

But remember your tooltip comes once you mouse over some other html control. So your tooltip is only visible in this case, actually Selenium does not allow you to click on hidden elements. So first you have to make it visible then click on it.

Hope it helps. Not sure this is what you are looking for.

Related