I'm having trouble performing a click operation on a button using JavaScript in Selenium Webdriver. Here is my JavaScipt code:
JavascriptExecutor js=(JavascriptExecutor) driver;
// js.executeScript("document.getElementById('customerid').click();");
js.executeScript("document.getElementsByClassName('ms-crm-ImageStrip-btn_off_lookup ms-crm-Lookup').click();");
Here is my HTML code:
td class="Lookup_RenderButton_td" style="width: 21px">
<img id="customerid" class="ms-crm-ImageStrip-btn_off_lookup ms-crm-Lookup" defaultviewid="{A9AF0AB8-861D-4CFA-92A5-C6281FED7FAB}" savedquerytype="" isdisplayonly="false" resolveemailaddress="0" showproperty="1" disableviewpicker="0" disablequickfind="0" disablemru="0" allowfilteroff="1" autoresolve="1" defaulttype="1" lookupstyle="single" lookupbrowse="0" lookuptypeicons="/_imgs/ico_16_1.gif?ver=-1567689440:/_imgs/ico_16_2.gif?ver=-1567689440" lookuptypenames="account:1:Account,contact:2:Contact" crmattributeid="{09d25a7a-420f-42f7-bad4-192edc51356a}" lookuptypes="1,2" attrpriv="7" attrname="customerid" style="ime-mode:auto" req="2" alt="Click to select a value for Customer Name." src="/_imgs/btn_on_lookup.png" title="Click to select a value for Customer Name." forcesubmit="false"/>
<a tabindex="-1" onclick="Mscrm.Utilities.click(previousSibling);" href="#" title="Click to select a value for Customer Name."/>
</td>
The exception I am receiving is:
Exception in thread "main" org.openqa.selenium.WebDriverException: document.getElementsByClassName(...).click is not a function
Command duration or timeout: 12 milliseconds
Could someone please check where I might be making a mistake?