首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将焦点切换为角弹出并滚动元素并单击

如何将焦点切换为角弹出并滚动元素并单击
EN

Stack Overflow用户
提问于 2020-04-22 13:19:26
回答 1查看 148关注 0票数 0

在我的页面中,当单击链接时,VW-Modal出现了--现在我必须滚动该弹出元素,然后单击,但是当我运行它时,它在VS中工作,但在运行VM - CCNet时不起作用。

代码:不工作

代码语言:javascript
复制
        ((IJavaScriptExecutor)Driver).ExecuteScript("arguments[0].scrollIntoView();", Driver.FindElement(button_RedoReasons_by));
        Driver.MoveToElement(button_RedoReasons_by);

        Driver.Click(button_RedoReasons_by);

( By.XPath("//@class='redo__reason'//contains(@class,‘container button_RedoReasons_by’));

DOM元素:

代码语言:javascript
复制
<!-- ngIf: vm.viewModel.redoPoup === true -->
<div class="job-progress-details redo-request-modal ng-scope" ng-if="vm.viewModel.redoPoup === true">
    <div class="popup-header">
        <h3 class="ng-binding">Order Redo Request [1434467]</h3>
        <a href="javascript:void(0);" class="close-popup" ng-click="vm.hideRedoRequest()">X</a>
    </div>
    <!-- NEW MODAL BODY -->
    <div class="popup-content">



        <!-- REDO ENTIRE ORDER -->
        <div ng-show="vm.sendRedoRequestCtrl.viewModel.isRedoEntireOrder === true" class="ng-hide">

            <div class="redo__option">
                <h3 class="redo__order-num ng-binding">Order Number 1434467</h3>

                <div class="redo__option-all" id="redo-option-all">
                    <div class="redo__input-label">
                        <input ng-model="vm.sendRedoRequestCtrl.viewModel.redoType" type="radio" id="redo-waitlist-all" name="redo-option-all" value="1" class="ng-pristine ng-untouched ng-valid">
                        <label for="redo-waitlist-all">To Waiting List</label>
                    </div>
                    <div class="redo__input-label">
                        <input ng-model="vm.sendRedoRequestCtrl.viewModel.redoType" type="radio" id="redo-artworkedit-all" name="redo-option-all" value="2" class="ng-pristine ng-untouched ng-valid">
                        <label for="redo-artworkedit-all">Artwork Edit</label>
                    </div>
                    <div class="redo__input-label">
                        <input ng-model="vm.sendRedoRequestCtrl.viewModel.redoType" type="radio" id="redo-print-all" name="redo-option-all" value="3" class="ng-pristine ng-untouched ng-valid">
                        <label for="redo-print-all">Straight to Print</label>
                    </div>
                </div>

                <div class="redo__reason-group--all">
                    <span class="redo__category--all">
                        <label for="redo-category-all">Redo Category</label>
                        <!-- ngIf: !vm.sendRedoRequestCtrl.viewModel.isLoaded --><select chosen="" data-ng-if="!vm.sendRedoRequestCtrl.viewModel.isLoaded" data-placeholder="Select redo category.." ng-model="vm.sendRedoRequestCtrl.viewModel.redoEntireOrderCategoryId" ng-options="p.Id as p.Name for p in vm.sendRedoRequestCtrl.viewModel.listRedoCategories track by p.Id" ng-change="vm.sendRedoRequestCtrl.changedRedoCategoryRedoEntire(vm.sendRedoRequestCtrl.viewModel.redoEntireOrderCategoryId)" class="ng-pristine ng-untouched ng-valid ng-scope ng-isolate-scope" style="display: none;"><option value="?" selected="selected"></option></select><div class="chosen-container chosen-container-single" style="width: 100%;" title=""><a class="chosen-single chosen-default"><span>Select redo category..</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off"></div><ul class="chosen-results"></ul></div></div><!-- end ngIf: !vm.sendRedoRequestCtrl.viewModel.isLoaded -->
                    </span>
                    <span class="redo__reason--all">
                        <label for="redo-reason-all">Redo Reason</label>
                        <!-- ngIf: !vm.sendRedoRequestCtrl.viewModel.isLoadedReason --><select chosen="" style="width: 80%; display: none;" data-ng-if="!vm.sendRedoRequestCtrl.viewModel.isLoadedReason" data-placeholder="Select redo reason.." ng-model="vm.sendRedoRequestCtrl.viewModel.redoEntireOrderReasonId" ng-options="cr.Id as cr.Name for cr in vm.sendRedoRequestCtrl.viewModel.listRedoReasons track by cr.Id" class="ng-pristine ng-untouched ng-valid ng-scope ng-isolate-scope"><option value="?" selected="selected"></option><option label="Sent to wrong person" value="8">Sent to wrong person</option></select><div class="chosen-container chosen-container-single" style="width: 100%;" title=""><a class="chosen-single chosen-default"><span>Select redo reason..</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off"></div><ul class="chosen-results"></ul></div></div><!-- end ngIf: !vm.sendRedoRequestCtrl.viewModel.isLoadedReason -->
                    </span>
                </div>


            </div>


            <div class="redo__action">
                <!-- ngIf: vm.sendRedoRequestCtrl.viewModel.showValidation === true -->
                <a href="" class="btn" ng-click="vm.sendRedoRequestCtrl.saveRedoRequest()">Redo Entire Order</a>
            </div>

        </div>

        <div ng-show="vm.sendRedoRequestCtrl.viewModel.isRedoEntireOrder === false">
            <div class="redo__option">
                <h3 class="redo__order-num ng-binding">Order Number 1434467</h3>
                <div class="redo__option-all">
                    <div class="redo__input-label">
                        <input ng-model="vm.sendRedoRequestCtrl.viewModel.redoType" type="radio" id="redo-waitlist" value="1" class="ng-pristine ng-untouched ng-valid" name="49">
                        <label for="redo-waitlist">To Waiting List</label>
                    </div>
                    <div class="redo__input-label">
                        <input ng-model="vm.sendRedoRequestCtrl.viewModel.redoType" type="radio" id="redo-artworkedit" value="2" class="ng-pristine ng-untouched ng-valid" name="50">
                        <label for="redo-artworkedit">Artwork Edit</label>
                    </div>
                    <div class="redo__input-label">
                        <input ng-model="vm.sendRedoRequestCtrl.viewModel.redoType" type="radio" id="redo-print" value="3" class="ng-pristine ng-untouched ng-valid" name="51">
                        <label for="redo-print">Straight to Print</label>
                    </div>
                </div>
            </div>



                        <ul class="job-item__redo">
                            <li class="redo__qty">
                                <label for="redo-qty-item-1">Quantity</label>
                                <select style="min-width: 100px;" ng-model="redoItem.RedoQty" ng-options="quantity as quantity for quantity in vm.sendRedoRequestCtrl.getReoJobQuantity(redoItem.Quantity)" class="ng-pristine ng-untouched ng-valid"><option label="1" value="number:1">1</option></select>
                            </li>
                            <li class="redo__category">
                                <label for="redo-category-item-1">Redo Category</label>
                                <select chosen="" data-placeholder="Select redo category.." data-ng-model="redoItem.SelectedCategoryId" data-ng-options="p.Id as p.Name for p in vm.sendRedoRequestCtrl.viewModel.listRedoCategories track by p.Id" data-ng-change="vm.sendRedoRequestCtrl.changedRedoCategory(redoItem)" class="ng-pristine ng-untouched ng-valid ng-isolate-scope" style="display: none;"></select><div class="chosen-container chosen-container-single" style="width: 100%;" title=""><a class="chosen-single chosen-default"><span>Select redo category..</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off"></div><ul class="chosen-results"></ul></div></div>
                            </li>
                            <li class="redo__reason">
                                <label for="redo-reason-item-1">Redo Reason </label>
                                <!-- ngIf: !redoItem.isLoaded --><select style="width: 80%; display: none;" chosen="" data-ng-if="!redoItem.isLoaded" data-placeholder="Select redo reason.." data-ng-model="redoItem.selectedReasonId" data-ng-options="c.Id as c.Name for c in redoItem.listRedoReasons" class="ng-pristine ng-untouched ng-valid ng-scope ng-isolate-scope"><option label="Bad gluing" value="number:50">Bad gluing</option><option label="Bad cutting" value="number:51">Bad cutting</option></select><div class="chosen-container chosen-container-single" style="width: 100%;" title=""><a class="chosen-single chosen-default"><span>Select redo reason..</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off"></div><ul class="chosen-results"></ul></div></div><!-- end ngIf: !redoItem.isLoaded -->
                            </li>
                        </ul>

                    </div>
                    <!-- ngIf: $index > 0 -->
                </li>
            </ul>


        </div>
    </div>
</div>
<!-- end ngIf: vm.viewModel.redoPoup === true -->
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-22 17:45:48

您的XPath表达式似乎不正确,因为没有提供通配符。您可以尝试添加一些睡眠到您的脚本。

代码语言:javascript
复制
WebElement element = driver.findElement(By.xpath("//*[@class='redo__reason']//*[contains(@class, 'chosen-container')]"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
Thread.sleep(5000); 
Driver.MoveToElement(element);
Thread.sleep(5000); 
Driver.Click(element);

与“预期条件”类似的东西可能更优雅:

代码语言:javascript
复制
new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*[@class='redo__reason']//*[contains(@class, 'chosen-container')]"))).Click()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61366155

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档