Selenium Webdriver - 无法点击md对话框元素

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.5/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.5/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/2.2.0/knockout-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.1/d3.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.20/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<div class="cdk-overlay-container">
<div class="cdk-overlay-backdrop cdk-overlay-dark-backdrop cdk-overlay-backdrop-showing">
</div>
<div class="cdk-global-overlay-wrapper" style="justify-content: center; align-items: center;">
<div id="cdk-overlay-4" class="cdk-overlay-pane" dir="ltr" style="position: static; width: 500px; pointer-events: auto;">
<md-dialog-container class="mat-dialog-container" role="dialog">
<cdk-focus-trap>
<!--template bindings={}-->
<div tabindex="0">
</div>
<div class="cdk-focus-trap-content">
<!--template bindings={}-->
<app-dialog _nghost-wcd-65="">
<h1 _ngcontent-wcd-65="" md-dialog-title="" class="mat-dialog-title">
Confirm
</h1>
<hr _ngcontent-wcd-65="">
<div _ngcontent-wcd-65="" md-dialog-content="" class="mat-dialog-content">
Are you sure to become Tech Leader of 6757657?
</div>
<hr _ngcontent-wcd-65="" class="bottomLine">
<div _ngcontent-wcd-65="" class="bottomSection mat-dialog-actions" md-dialog-actions="">
<button _ngcontent-wcd-65="" class="btn">
Yes
</button>
<button _ngcontent-wcd-65="" class="btn" md-dialog-close="" type="button" aria-label="Close dialog">
No
</button>
</div>
</app-dialog>
</div>
<!--template bindings={}-->
<div tabindex="0">
</div>
</cdk-focus-trap>
</md-dialog-container>
</div>
</div>
</div>

我不知道为什么它不想点击显示的对话框上的“是”按钮 . 我的代码看起来像这样:

String parentWindowHandler = SeleniumExecutor.getDriver().getWindowHandle(); 
        String subWindowHandler = null;

        Set<String> handles = 
SeleniumExecutor.getDriver().getWindowHandles(); 
        Iterator<String> iterator = handles.iterator();
        while (iterator.hasNext()) {
            subWindowHandler = iterator.next();
        }

SeleniumExecutor.getDriver().switchTo().window(subWindowHandler);

        projectPage.confirmAddingTechLead();

        SeleniumExecutor.getDriver().switchTo().window(parentWindowHandler);
}

public void confirmAddingTechLead(){
projectsPageLocators.yes_techLead.click();}

不知道为什么“是”元素没有找到,我认为我的定位器很好,它必须是handeling对话窗口,但我尝试了几个不同的方法,我总是得到以下错误:

rg.openqa.selenium.NoSuchElementException:没有这样的元素:无法定位元素:{“method”:“xpath”,“selector”:“html / body / div [2] / div [2] / div / md- dialog-container / cdk-focus-trap / div [2] / app-dialog / div [2] / button [1]“}(会话信息:chrome = 57.0.2987.98)(驱动程序信息:chromedriver = 2.28.455520( cc17746adff54984afff480136733114c6b3704b),platform = Windows NT 10.0.14393 x86_64)(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:4.07秒有关此错误的文档,请访问:http://seleniumhq.org/exceptions/ no_such_element.html构建信息:版本:'3.0.1',修订版:'1969d75',时间:'2016-10-18 09:49:13 -0700'系统信息:主机:'LPACZEK-RZE',ip:' 10.10.32.72',os.name:'Windows 10',os.arch:'amd64',os.version:'10 .0',java.version:'1.8.0_121'驱动程序信息:org.openqa.selenium.chrome . ChromeDriver功能[{applicationCacheEnabled = false,rotate = false,mobileEmulationEnabled = false,networkConnectionEnabled = false,chrome = {chrome driverVersion = 2.28.455520(cc17746adff54984afff480136733114c6b3704b),userDataDir = C:\ Users \ lpaczek \ AppData \ Local \ Temp \ scoped_dir2256_6186},takesHeapSnapshot = true,pageLoadStrategy = normal,databaseEnabled = false,handlesAlerts = true,hasTouchScreen = false,version = 57.0 .2987.98,platform = XP,browserConnectionEnabled = false,nativeEvents = true,acceptSslCerts = true,locationContextEnabled = true,webStorageEnabled = true,browserName = chrome,takesScreenshot = true,javascriptEnabled = true,cssSelectorsEnabled = true,unexpectedAlertBehaviour =}]会话ID: 1f5bf251b3097b95ce337030cad3fab8 ***元素信息:{Using = xpath,value = html / body / div [2] / div [2] / div / md-dialog-container / cdk-focus-trap / div [2] / app-dialog / div [2] / button [1]} at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java :45)在java.lan org.openqa.selenium.remote上的org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)中的g.reflect.Constructor.newInstance(Constructor.java:423) . (ErrorHandler.java:ErrorHandler.java:ErrorHandler.java: 168)org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:368)atg.openqa.selenium.remote.RemoteWebDriver位于org.openqa.selenium的.findElementByXPath(RemoteWebDriver.java:473) . 在org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)上的$ ByXPath.findElement(By.java:361) . 位于com.sun.proxy的org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)中的openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69) . $ Proxy14 .getCoordinates(未知来源)org.openqa.selenium.interactions.internal.MouseAction.getActionLocation(MouseAction.java:51)a org.openqa.selenium.interactions.MoveMouseAction.perform(MoveMouseAction.java:39)org.openqa.selenium.interactions.CompositeAction.perform(CompositeAction.java:50)at org.openqa.selenium.interactions.Actions.perform (Actions.java:373)在pages.executors.ProjectPage.confirmAddingTechLead(ProjectPage.java:99)的steps.EditProjectSteps.iClickYes(EditProjectSteps.java:138)at.And我点击是(C:/ Users / lpaczek /文档/卑谬/ SRC /测试/资源/任务1 / EditProject.feature:32)

回答(0)