1

there is a pop up after adding item to cart but it does not pop sometimes how can i have the loop, if there is pop up then click the close or continue button or just click the background to dismiss it. if it does not pop then continue next step. below is the element, it is pretty long. please help to check

<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>
user2201789
  • 1,083
  • 2
  • 20
  • 45

4 Answers4

1

Here is the logic.

// 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();
}
supputuri
  • 13,644
  • 2
  • 21
  • 39
  • Yeah, I realized and updated the answer just before you post the comment :-), were you able to click desired button with this logic? – supputuri May 01 '19 at 13:10
  • i tried but not working 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(); } – user2201789 May 01 '19 at 13:12
  • did you get any error message? does the popup there in iframe? – supputuri May 01 '19 at 13:14
  • how to check if it is iframe? – user2201789 May 01 '19 at 13:16
  • Did you got the no such element exception? check my answer [how to check if element present in iframe](https://stackoverflow.com/questions/55536851/is-there-a-way-to-search-webelement-on-a-main-window-first-if-not-found-then-s/55537186#comment97778812_55537186) – supputuri May 01 '19 at 13:20
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/192686/discussion-between-supputuri-and-user2201789). – supputuri May 01 '19 at 20:09
1

Try the following code.Hope this will work.

To click on continue try this

    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);


}

//To click on No Thanks try this

  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);
}

//To close the popup

   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);
}
KunduK
  • 32,888
  • 5
  • 17
  • 41
  • To click on continue or close does not work. i saw the Continue or x button highlighted, but it does not click and proceed. – user2201789 May 02 '19 at 07:24
  • Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element is not clickable at point (944, 68). Other element would receive the click:
    ...
    – user2201789 May 02 '19 at 07:52
  • So it identifies the element but not clicking.try action class or Java script executor to click.it should click. – KunduK May 02 '19 at 08:13
  • @user2201789 : Updated the code with action class and JS executor try now.hope this will click. – KunduK May 02 '19 at 08:42
0

I am using 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

Sid
  • 3,749
  • 7
  • 29
  • 62
  • don't use bare except and then swallow the exception – Corey Goldberg May 01 '19 at 13:23
  • @CoreyGoldberg yes I agree, in the code which I use I am printing/logging the error. However in this case I assumed it would not be required because of the error would be inconsequential to progress/performance of the code? – Sid May 01 '19 at 15:16
0

after trying many methods. below is working. i add a wait element then add one more click.

        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();
user2201789
  • 1,083
  • 2
  • 20
  • 45