gpt4 book ai didi

在 Java Selenium Webdriver 中使用 Javascript

转载 作者:行者123 更新时间:2023-11-30 16:14:03 27 4
gpt4 key购买 nike

我无法通过 selenium Webdriver 中的 javascript 对按钮执行单击操作。下面是我的 javaScript 代码

 JavascriptExecutor js=(JavascriptExecutor) driver;  
// js.executeScript("document.getElementById('customerid').click();");

js.executeScript("document.getElementsByClassName('ms-crm-ImageStrip-btn_off_lookup ms-crm-Lookup').click();");

下面是我的HTML代码

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>

我得到的异常:

Exception in thread "main" org.openqa.selenium.WebDriverException: document.getElementsByClassName(...).click is not a function
Command duration or timeout: 12 milliseconds

任何人都可以检查我哪里做错了吗?

最佳答案

你可以使用任何一个:

driver.execute_script("document.getElementsByClassName('ms-crm-ImageStrip-btn_off_lookup ms-crm-Lookup')[0].click();")   

content = driver.find_element_by_class_name('ms-crm-ImageStrip-btn_off_lookup ms-crm-Lookup')
content.click()

关于在 Java Selenium Webdriver 中使用 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35792237/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com