ex-expat
ex-expat

Reputation: 81

Selenium/VBA: clicking xpath using Javascript

I am trying to execute Javascript in order to click an element in VBA. The element is in a web app that only runs in IE explorer. I am currently interacting with the element using the Selenium Type library with the following code :

FindElementByXPath("//*[contains(text(), 'Revenue Report')]"

I am able to click the element successfully, but nothing actually happens when I do.

I can easily accomplish what I need to using WebDriver (java) with the following code:

JavascriptLibrary jsLib = new JavascriptLibrary();

WebElement ele2 = driver.findElement(By.xpath("//*[contains(text(), 'Revenue Report')]"));

jsLib.callEmbeddedSelenium(driver, "triggerMouseEventAt", ele2, "click", "0,0");

I have used the "Execute Script" method in the Selenium Type library successfully in the past by using the following:

ExcuteScript("document.getElementByID("element").click();")

but I don't know how to make it work using xpath. Any help would be greatly appreciated.

The following is some source code I used to locate the element:

<TR targetURL="/Bafaefice/TTTaefaeTT/TaefTTT/Rev/RevInput_Page1.asp?HelpURL=/WebHelp/NonMaaefnager/Sign_Onto_Back_Office.htm?Revenue_Report.htm&amp;ScreenID=RVN-002&amp;ScreenName=Revenue Report&amp;ResourceID=397600022" targetFrame="ApaefaefplicatifaonFrame" screenName="Revenue Report" screenID="RVN-002" matraApp="true"><TD class=popupMenuCell noWrap>Revenue Report</TD></TR>

<TD class=popMenCe noWrap>Revenue Report</TD>

Upvotes: 1

Views: 2774

Answers (1)

Saurabh Gaur
Saurabh Gaur

Reputation: 23805

You should try as below :-

 ExcuteScript("arguments[0].click();",ele2)

Where ele2 uses as already found element located by Xpath

Upvotes: 1

Related Questions