请注意,
好吧,我的html代码是
<button class="header-nav__get-result popupBtn" data-mfp-src="#popupResult" onclick="(dataLayer = window.dataLayer || []).push({'pPath': location.pathname + 'virtual/send-results/', 'event': 'GAPageview'});">
<div class="icon-analysis-wrapper">
<svg class="icon icon-analysis" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 203.7 272.16">
<path class="icon-analysis__colba" d="M158.34,238.56,100.88,147v-28.7h20.06V88.49H40.88v29.8H60.72V147L6.22,238.56a20.06,20.06,0,0,0,17.36,30.1H141A20.07,20.07,0,0,0,158.34,238.56Z"></path>
<path class="icon-analysis__liquid" d="M158.34,238.56l-24.73-39.41h0l-5.87-9.35c-13-1.27-26.24-1.44-40.06,1.91-8.5,2.06-13.67,5.08-21.07,8.41a63.6,63.6,0,0,1-26.21,5.73,50.58,50.58,0,0,1-13.69-1.71l-5.13,8.6h0L6.22,238.56a20.06,20.06,0,0,0,17.36,30.1H141A20.07,20.07,0,0,0,158.34,238.56Z"></path>
<path class="icon-analysis__bubble3" d="M200.2,95.32a20,20,0,0,1-40,.9q0-.45,0-.9a20,20,0,0,1,40,0Z"></path>
<path class="icon-analysis__bubble2" d="M166.22,27.65a24.64,24.64,0,1,1-49.27,1q0-.49,0-1a24.64,24.64,0,0,1,49.27,0Z"></path>
<path class="icon-analysis__bubble1" d="M81.51,49a15.41,15.41,0,0,1-30.82,0c0-7.67,6.91-15.41,15.41-15.41A15.42,15.42,0,0,1,81.51,49Z"></path>
<path class="icon-analysis__bubble0" d="M92.28,163.17a10,10,0,1,1-10-10A10,10,0,0,1,92.28,163.17Z"></path>
</svg>
</div>
<span>Get results</span>
</button>
当我尝试点击这个按钮时,它失败了,因为点击不起作用。
final By locatorButtonGetResults = By.xpath("//div[@id='bvi-block']/header/div[@class='header-bottom']/button[@class='header-nav__get-result popupBtn']");
WebElement buttonGetResults =
wait.until(ExpectedConditions.elementToBeClickable(locatorButtonGetResults));
final Actions actions = new Actions(driver);
actions.moveToElement(buttonGetResults).click(buttonGetResults).build().perform();
我试着通过点击按钮GetResults和JavascriptExecutor来点击。这两种方法也都失败了。怎么了?我该怎么做才能通过考试?
该按钮打开放大弹出窗口。要打开这个弹出窗口,我需要运行js脚本:
jsExecutor.executeScript("$( document ).ready(function() {$.magnificPopup.open({" +
"items: {" +
"src: '#popupResult'}" +
"});});");
<button class="header-nav__get-result popupBtn"
有两个类,因此使用xpath表达式/button[@class='header-nav__get-result popupBtn']
不是一个好方法。
试试下面的xpath演示:
//button[contains(@class, 'header-nav__get-result') and contains(@class, 'popupBtn')]
或cssSelect:
button.header-nav__get-result.popupBtn