我知道图像按钮的 ID,但仍然无法点击:
driver.findElement(By.id("its Id")).click()
无法提供网站链接,因为它不是公共(public)网站,而是粘贴指定 Web 元素的 HTML。
<div ondragstart="var e=window.event;e.cancelBubble=true;e.returnValue=false;return false;" draggable="false" id="WD0191" ct="B" lsdata="{4:'Add\x20All',10:true,12:'\x2fsap\x2fpublic\x2fbc\x2fur\x2fnw5\x2fthemes\x2f\x7ecache\x2d20171002133000\x2fBase\x2fbaseLib\x2fsap_belize\x2fsvg\x2flibs\x2fSAPGUI\x2dicons.svg\x23s_pagedo'}" lsevents="{Press:[{ResponseData:'delta',ClientAction:'submit'},{}]}" role="button" aria-labelledby="WD0191-arialabel" title="Add All " tabindex="0" ti="0" class="lsButton lsTbarBtnStd urInlineMetricTop urNoUserSelect urBtnRadius lsButton--onlyImage urBtnImgBgColor lsButton--design-standard urBtnStd">
<span id="WD0191-cnt" class="urNoUserSelect lsButton--content lsControl--centeraligned " style="pointer-events:none;">
<svg data-sap-ls-svg-inline="true" data-sap-ls-svg-inlinehtmlexchange="true" id="WD0191-img" alt="Add All " tabindex="-1" ti="-1" focusable="false" preserveAspectRatio="none" viewBox="0 0 100 100" class="urSvgAppIconMetric urSvgAppIconColorBase urSvgAppIconVAlign urImgBtn lsButton__image" style="nop:nop;margin-top: 0px;;nop:nop;">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#_SAPGUI-icons_1_s_pagedo"></use>
</svg>
<span class="lsButton--onlyImage-pusher" style="display:inline-block;width:0;"> </span>
</span>
<span id="WD0191-arialabel" style="display:none;visibility:hidden;">Add All</span>
</div>
有人可以建议我如何通过其他方式点击它吗?
更新:当我尝试使用 click() 单击它时,它只是将鼠标移动到该元素。所以是的,我确信它正确地识别了该项目。但不知何故,使用 webdriver 单击它不会给出与手动单击相同的结果。
我认为因为当我使用 webdriver 单击它时,为该元素编写的 javascript 没有被触发,这就是为什么我没有得到想要的结果。
我尝试过使用:
new Actions(driver).moveToElement(input).click().perform();
但没有结果。
更新:按钮的用途以及在大图中它位于哪个 div 标签内。 此按钮位于一个表格内,该表格分为两部分,在表格的第一部分中,您根据某些搜索条件获取结果,如果它们相关,您可以使用此图像按钮将它们复制到表格的第二部分。
最佳答案
尝试使用 JavascriptExecutor:
WebElement ele1 = driver.findElement(By.id("ITS ID"));
JavascriptExecutor clickbtn = (JavascriptExecutor)driver;
clickbtn.executeScript("arguments[0].click();", ele1);
关于javascript - 我知道图像按钮的 ID,但仍然无法点击它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48930163/