как нажать кнопку «Закрыть» или «Подтвердить», или «Фон», чтобы закрыть всплывающее окно. - PullRequest
1 голос
/ 01 мая 2019

после добавления товара в корзину появляется всплывающее окно, но иногда оно не появляется Как я могу получить цикл, если есть всплывающее окно, нажмите кнопку «Закрыть» или «Продолжить» или просто нажмите фон, чтобы закрыть его. если это не появляется, тогда продолжите следующий шаг. ниже элемент, он довольно длинный. помогите пожалуйста проверить

<div class="a-popover-wrapper"><header class="a-popover-header"><h4 class="a-popover-header-content" id="a-popover-header-6">Add to Order</h4><button data-action="a-popover-close" class=" a-button-close a-declarative" aria-label="Close"><i class="a-icon a-icon-close"></i></button></header><div class="a-popover-inner" id="a-popover-content-6" style="height: auto; overflow-y: auto;">
    <div id="abb-interstitial" class="a-section abb-interstitial">
 
                            <div id="abb-intl-product-view-B07KTYTTG9" class="a-section abb-intl-product-view" style="display: block;">

 <!-- only true in interstitial popovers -->

<div class="a-row">
    <div class="a-column a-span4 a-text-center abb-product-view-image-container">
        <img src="https://images-na.ssl-images-amazon.com/images/I/31STSohmOiL._SL160_.jpg" class="a-image-wrapper a-manually-loaded abb-product-image" id="" alt="" data-a-image-source="https://images-na.ssl-images-amazon.com/images/I/31STSohmOiL._SL160_.jpg" data-a-hires="https://images-na.ssl-images-amazon.com/images/I/31STSohmOiL._SL500_.jpg">
    </div>
    <div class="a-column a-span8 a-span-last">
        <h3 class="a-spacing-none">
            <a class="a-link-normal abb-product-title" target="_blank" rel="noopener" href="/dp/B07KTYTTG9/ref=ods_dabb_B07KTYTTG9_productInfo">
                AppleCare+ for 13-inch MacBook Pro (3 Years)
            </a>
        </h3>
        <div class="a-section a-spacing-micro abb-product-merchant-container">
            <span class="a-color-secondary">
                from
                <span class="abb-product-merchant">Amazon  Digital  Services LLC</span>
            </span>
        </div>
        <div class="a-section a-spacing-micro abb-product-reviews">
  
<style type="text/css">
    /* 
    * Fix for UDP-1061. Average customer reviews has a small extra line on hover 
    * https://omni-grok.amazon.com/xref/src/appgroup/websiteTemplates/retail/SoftlinesDetailPageAssets/udp-intl-lock/src/legacy.css?indexName=WebsiteTemplates#40
    */
    .noUnderline a:hover { 
        text-decoration: none; 
    }
</style>


        <div id="averageCustomerReviews" class="a-spacing-none" data-asin="B07KTYTTG9" data-ref="dpx_acr_pop_">
            
            
            
                
                
                    



        <span class="a-declarative" data-action="acrStarsLink-click-metrics" data-acrstarslink-click-metrics="{}">
            





    <span id="acrPopover" class="reviewCountTextLinkedHistogram noUnderline" title="4.0 out of 5 stars">
        <span class="a-declarative" data-action="a-popover" data-a-popover="{&quot;max-width&quot;:&quot;700&quot;,&quot;closeButton&quot;:&quot;false&quot;,&quot;position&quot;:&quot;triggerBottom&quot;,&quot;url&quot;:&quot;/gp/customer-reviews/widgets/average-customer-review/popover/ref=dpx_acr_pop_?contextId=dpx&amp;asin=B07KTYTTG9&quot;}">
            <a href="javascript:void(0)" class="a-popover-trigger a-declarative">
                

<i class="a-icon a-icon-star a-star-4"><span class="a-icon-alt">4.0 out of 5 stars</span></i>
                
            <i class="a-icon a-icon-popover"></i></a>
        </span>
        <span class="a-letter-space"></span>
    </span>


        </span>
        <span class="a-letter-space"></span>
        
        

        

        

        
        
        
        
        
        
        
            
            
                <span class="a-declarative" data-action="acrLink-click-metrics" data-acrlink-click-metrics="{}">
                    <a id="acrCustomerReviewLink" class="a-link-normal" href="#customerReviews">
                        <span id="acrCustomerReviewText" class="a-size-base">2 customer reviews</span>
                    </a>
                </span>
            
                <script type="text/javascript">
                    P.when('A', 'ready').execute(function(A) {
                        A.declarative('acrLink-click-metrics', 'click', { "allowLinkDefault" : true }, function(event){
                            if(window.ue) {
                                ue.count("acrLinkClickCount", (ue.count("acrLinkClickCount") || 0) + 1);
                            }
                        });
                    });
                </script>
            
            
            
            
        
        
        <script type="text/javascript">
            P.when('A', 'cf').execute(function(A) {
                A.declarative('acrStarsLink-click-metrics', 'click', { "allowLinkDefault" : true },  function(event){
                    if(window.ue) {
                        ue.count("acrStarsLinkWithPopoverClickCount", (ue.count("acrStarsLinkWithPopoverClickCount") || 0) + 1);
                    }
                });
            });
        </script>


                
            
        </div>
    


        </div>
        <div class="a-section a-spacing-base abb-product-price">
            <span class="a-size-medium a-color-secondary abb-product-list-price a-text-strike">
                
            </span>

            <span class="a-size-medium a-color-price abb-product-buying-price">
                $269.00
            </span>
        </div>

        

         
            
            
                
                <div class="a-section abb-product-feature-bullets">
                    <ul>
                        
                            
                                <li>AppleCare product must be purchased with an applicable Apple device. Terms &amp; Conditions will be delivered via email post-enrollment and can be downloaded through your Digital Items Page (Your Account--&gt;Games and Software).</li>
                            
                        
                            
                                <li>AppleCare+ will automatically be enrolled at time of purchase, and Proof of Coverage will be emailed within 3 days after your device ships.</li>
                            
                        
                            
                                <li>AppleCare+ for Mac extends your coverage to three years from your AppleCare+ purchase date and adds up to two incidents of accidental damage coverage</li>
                            
                        
                            
                                <li>Each incident of accidental damage coverage is subject to a service fee of $99 for screen damage or external enclosure damage, or $299 for other damage, plus applicable tax</li>
                            
                        
                            
                                <li>Get 24/7 priority access to Apple experts by chat or phone</li>
                            
                        
                            
                                <li>Onsite repair for desktop computers: Request that a technician come to your work site</li>
                            
                        
                            
                                <li>Mail-in repair for portable computers: Mail in your Mac using a prepaid shipping box provided by Apple</li>
                            
                        
                            
                                <li>Carry-in repair: Take your Mac to an Apple Store or other Apple Authorized Service Provider</li>
                            
                        
                            
                                <li>Hardware coverage for your Mac computer, battery, included accessories such as the power adapter, Apple memory (RAM), AirPort, and Apple USB SuperDrive</li>
                            
                        
                            
                                <li>Software support for using macOS and iCloud, quick how-to questions about Apple-branded apps, such as Photos, iMovie, GarageBand, Pages, Numbers, Keynote, and more, connecting to printers and AirPort networks</li>
                            
                        
                    </ul>
                </div>
            
        



    </div>
</div>



                                












<div class="a-row">
    <div class="a-column a-span8 a-push4">
        <div class="a-section a-spacing-mini a-spacing-top-base abb-intl-product-cta">

            <div class="a-row a-spacing-top-base">
                <div data-asin="B07KTYTTG9" class="a-checkbox abb-intl-product-ato"><label><input type="checkbox" name="" value="" autocomplete="off"><i class="a-icon a-icon-checkbox"></i><span class="a-label a-checkbox-label">
                    <span class="a-text-bold">Add AppleCare+ for 13-inch MacBook Pro (3 Years) to your order</span>
                </span></label></div>
            </div>

        </div>
    </div>
</div>



                            </div>
                        
                    

                

            

                
                
                
                

                

            

                
                
                
                

                

            

                
                
                
                

                

            

                
                
                
                

                

            
        

        
            
            






<div id="abb-intl-pop-cta" class="a-section a-spacing-base">
    <div class="a-row">
        

            

            
                <div class="a-column a-span8 a-push4">

                    <span class="a-button a-button-primary abb-intl-ato abb-intl-continue" id="a-autoid-13"><span class="a-button-inner"><input class="a-button-input" type="submit" aria-labelledby="a-autoid-13-announce"><span class="a-button-text a-text-center" aria-hidden="true" id="a-autoid-13-announce">
                        Continue
                    </span></span></span>

                    <span class="a-button a-button-base abb-intl-decline aok-hidden" id="a-autoid-14"><span class="a-button-inner"><input class="a-button-input" type="submit" aria-labelledby="a-autoid-14-announce"><span class="a-button-text a-text-center" aria-hidden="true" id="a-autoid-14-announce">
                        No thanks
                    </span></span></span>

                </div>
            

        
    </div>
</div>

        

    </div>

</div></div>

Ответы [ 4 ]

1 голос
/ 01 мая 2019

Попробуйте следующий код. Надеюсь, это сработает.

Чтобы нажать продолжить попробуйте

    if (driver.findElements(By.cssSelector("div.a-popover-wrapper")).size()>0){
    WebElement element=driver.findElement(By.Xpath("//span[normalize-space(.)='Continue']/parent::span/input[@class='a-button-input']"));
    Actions action = new Actions(driver);
    action.moveToElement(element).click().build().perform();

}

OR

if (driver.findElements(By.cssSelector("div.a-popover-wrapper")).size()>0){
    WebElement element=driver.findElement(By.Xpath("//span[normalize-space(.)='Continue']/parent::span/input[@class='a-button-input']"));
    JavascriptExecutor executor = (JavascriptExecutor) driver;
    executor.executeScript("arguments[0].click();",element);


}

// Нажать на Нет, спасибо Попробуйте это

  if (driver.findElements(By.cssSelector("div.a-popover-wrapper")).size()>0){
    WebElement element=driver.findElement(By.Xpath("//span[normalize-space(.)='No thanks']/parent::span/input[@class='a-button-input']"));
    Actions action = new Actions(driver);
    action.moveToElement(element).click().build().perform();
}

OR

if (driver.findElements(By.cssSelector("div.a-popover-wrapper")).size()>0){
    WebElement element=driver.findElement(By.Xpath("//span[normalize-space(.)='No thanks']/parent::span/input[@class='a-button-input']"));
    JavascriptExecutor executor = (JavascriptExecutor) driver;
    executor.executeScript("arguments[0].click();",element);
}

// К закрыть всплывающее окно

   if (driver.findElements(By.cssSelector("div.a-popover-wrapper")).size()>0){
     WebElement element=driver.findElement(By.cssSelector("i.a-icon.a-icon-close"));
     Actions action = new Actions(driver);
    action.moveToElement(element).click().build().perform();
}

OR

if (driver.findElements(By.cssSelector("div.a-popover-wrapper")).size()>0){
     WebElement element=driver.findElement(By.cssSelector("i.a-icon.a-icon-close"));
    JavascriptExecutor executor = (JavascriptExecutor) driver;
    executor.executeScript("arguments[0].click();",element);
}
0 голосов
/ 02 мая 2019

после попытки многих методов. ниже работает. я добавляю элемент ожидания затем добавьте еще один клик.

        WebDriverWait wait2 = new WebDriverWait(driver, 10);
        wait2.until(ExpectedConditions.elementToBeClickable(By.id("a-autoid-13")));
        driver.findElement(By.cssSelector("i.a-icon.a-icon-close")).click();
0 голосов
/ 01 мая 2019

Вот логика.

// change the action based on scenario
String action = 'Continue';
if (driver.findElements(By.Xpath("//div[@class='a-popover-wrapper']")).size()>0){
    driver.findElement(By.Xpath("//div[@class='a-popover-wrapper']//span[@class='a-button-text a-text-center' and normalize-space(.)='" + action + "']")).click();
}
0 голосов
/ 01 мая 2019

Я использую Python:

def escape_pop(driver):
    try:
         if len(str(driver.find_element_by_class_name("a-popover-wrapper"))) > 0: # check if popup is present
            actions = ActionChains(driver)
            actions.send_keys(Keys.ESCAPE).perform()
    except:
      pass

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...