1

I am confused a lot here. i am unable to click on a button. Maybe it is on different frame. But as i tried to use switch statement i got an error that no such frame found. And if i directly run my code by clicking on the button them i get's an error:- Unable to locate element: //*[@id='dutch_popupBtn']

The HTML is:-

<div class="horiZontalScroll">
    <table class="table highlight makeGapTable buyerTable setHeightThTd scrollTableRow">
        <thead>
            <tr class="auctionTable prodActName">
                <th class="active_purchase"><strong>Product</strong> <small>Auction</small></th>
                <th class="active_purchase"><strong>Volume</strong><small>ID number</small></th>
                <th class="active_purchase"><strong>Starting Price</strong> <small>Minimum Price</small></th>
                <th class="active_purchase"><strong>Bids</strong> <small>Current Price</small> </th>
                <!--<th><strong>Bids/Bidders</strong></th>-->
                <th class="active_purchase"><strong>Duration</strong></th>
                <th class="active_purchase"><strong>Action</strong></th>
            </tr>
        </thead>
        <tbody id="active_auctions" class="mCustomScrollbar _mCS_3 mCS_no_scrollbar">
            <div id="mCSB_3" class="mCustomScrollBox mCS-light mCSB_vertical mCSB_inside" tabindex="0">
                <div id="mCSB_3_container" class="mCSB_container mCS_y_hidden mCS_no_scrollbar_y" style="position:relative; top:0; left:0;" dir="ltr">
                    <tr class="auctionTable rowHref prodActName" style="cursor: pointer;" id="auctionlistrow621" href="/buyer/auction/auctiondetail/id/621">

                        <td class="active_purchase">
                            <strong>360A iodide</strong>

                            <small style="font-size: 75%;">Dutch Auction</small>
                        </td>

                        <td class="active_purchase"> 12.000 fl oz <small style="font-size: 75%;">ID 621</small>
                        </td>

                        <td class="active_purchase"> 10.000 EUR/fl oz
                            <small>100 EUR/fl oz</small>
                        </td>

                        <td class="active_purchase">
                            <small class="">9.600 EUR/fl oz</small>

                        </td>

                        <td class="active_purchase">

                            <span class="duration_left" data-id="621" data-bind="11d 20h 8m <br></span>">11d 20h 8m
                            <br>
                            </span> <small>10.05.2018 22:10:54</small>
                        </td>

                        <td class="active_purchase actionIcons">

                            <a title="Place Bid" href="javascript:void(0)" id="dutch_popupBtn" data-bind="621"><i class="fa fa-gavel" noredirect="1"></i></a>
                            <i title="Remove Auction" class="fa fa-remove no auctionDeleteBtnClass" data-bind="621" noredirect="1"></i>
                            <a title="Contact Seller" href="javascript:void(0)" id="requestQues" data-params="{&quot;userid&quot;:&quot;343&quot;,&quot;name&quot;:&quot;Beta Zero&quot;,&quot;company&quot;:&quot;Clavax Zer0&quot;,&quot;membership&quot;:&quot;4&quot;,&quot;companyrevenue&quot;:&quot;&quot;}" data-auction="621"><i class="fa fa-envelope no" noredirect="1"></i></a>
                            <a title="Click to learn more" href="javascript:void(0);" data="dutch" class="tour_popupBtn" noredirect="1"><i class="fa fa-exclamation-circle" noredirect="1"></i></a>
                        </td>
                    </tr>

                    <tr class="auctionTable rowHref prodActName" style="cursor: pointer;" id="auctionlistrow615" href="/buyer/auction/auctiondetail/id/615">

                        <td class="active_purchase">
                            <strong>360A iodide</strong>

                            <small style="font-size: 75%;">Dutch Auction</small>
                        </td>

                        <td class="active_purchase"> 12.000 Liter <small style="font-size: 75%;">ID 615</small>
                        </td>

                        <td class="active_purchase"> 5.000 USD/Liter
                            <small>1.000 USD/Liter</small>
                        </td>

                        <td class="active_purchase">
                            <small class="">4.900 USD/Liter</small>

                        </td>

                        <td class="active_purchase">

                            <span class="duration_left" data-id="615" data-bind="4d 18h 40m <br></span>">4d 18h 40m
                            <br>
                            </span> <small>03.05.2018 20:42:57</small>
                        </td>

                        <td class="active_purchase actionIcons">

                            <a title="Place Bid" href="javascript:void(0)" id="dutch_popupBtn" data-bind="615"><i class="fa fa-gavel" noredirect="1"></i></a>
                            <i title="Remove Auction" class="fa fa-remove no auctionDeleteBtnClass" data-bind="615" noredirect="1"></i>
                            <a title="Contact Seller" href="javascript:void(0)" id="requestQues" data-params="{&quot;userid&quot;:&quot;343&quot;,&quot;name&quot;:&quot;Beta Zero&quot;,&quot;company&quot;:&quot;Clavax Zer0&quot;,&quot;membership&quot;:&quot;4&quot;,&quot;companyrevenue&quot;:&quot;&quot;}" data-auction="615"><i class="fa fa-envelope no" noredirect="1"></i></a>
                            <a title="Click to learn more" href="javascript:void(0);" data="dutch" class="tour_popupBtn" noredirect="1"><i class="fa fa-exclamation-circle" noredirect="1"></i></a>
                        </td>
                    </tr>

                </div>
                <div id="mCSB_3_scrollbar_vertical" class="mCSB_scrollTools mCSB_3_scrollbar mCS-light mCSB_scrollTools_vertical" style="display: none;">
                    <div class="mCSB_draggerContainer">
                        <div id="mCSB_3_dragger_vertical" class="mCSB_dragger" style="position: absolute; min-height: 30px; height: 0px; top: 0px;" oncontextmenu="return false;">
                            <div class="mCSB_dragger_bar" style="line-height: 30px;"></div>
                        </div>
                        <div class="mCSB_draggerRail"></div>
                    </div>
                </div>
            </div>
        </tbody>
    </table>
</div>

My code is :-

//driver.switchTo().frame("active_auctions");  
driver.findElement(By.xpath("//*[@id='dutch_popupBtn']")).click();
System.out.println("test"); 

The Error is :-

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: //*[@id='dutch_popupBtn']

Can anyone help me in clicking on the Place bid button. It would be very helpful.

Ali Azam
  • 2,047
  • 1
  • 16
  • 25
RAHUL
  • 398
  • 1
  • 6
  • 15

1 Answers1

2

As per the HTML you have shared and your code attempts I dont see any frame present by the name/id as active_auctions but to locate the element with id as dutch_popupBtn you need to induce WebDriverWait as follows :

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//td[@class='active_purchase actionIcons']//a[@id='dutch_popupBtn' and @title='Place Bid']/i"))).click();

Update

As per your comment update as you are finding that the focus is on the element but not clicking you can use the executeScript() method as follows :

WebElement myElement = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//td[@class='active_purchase actionIcons']//a[@id='dutch_popupBtn' and @title='Place Bid']/i")));
driver.execute_script("arguments[0].click();", myElement) 
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Ohh God.. U r good.. U have solved my problems a couple of times.. Thanks a lot.. BUT CAN U PLEASE EXPLAIN ME WHY HERE IT WAS NOT JUST STRAIGHT ND SIMPLE...?? – RAHUL Apr 28 '18 at 21:25
  • @RAHUL Incase of _NoSuchElementExeption_ refer this discussion [NoSuchElementExeption, selenium unable to locate element](https://stackoverflow.com/questions/48471321/nosuchelementexeption-selenium-unable-to-locate-element/48472940#48472940) – undetected Selenium Apr 28 '18 at 21:29
  • the code has stopped working now.. It worked for the first time but not working now... The focus is on the button but not clicking to open the form... – RAHUL Apr 28 '18 at 22:11
  • @RAHUL Checkout my updated answer and let me know the status – undetected Selenium Apr 29 '18 at 07:47
  • the code is working fine on refreshing the page by driver.navigate().refresh(); else it isn't reading the line.. new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//td[@class='active_purchase actionIcons']//a[@id='dutch_popupBtn' and @title='Place Bid']/i"))).click(); Why it is so? – RAHUL Apr 30 '18 at 09:37
  • I would say instead of fixing through `refresh()` use the second option using `execute_script()` method. – undetected Selenium Apr 30 '18 at 09:42