Селен: - Невозможно найти элемент - PullRequest
0 голосов
/ 28 апреля 2018

Я очень смущен здесь. Я не могу нажать на кнопку. Может быть, это на другом кадре. Но когда я попытался использовать оператор switch, я получил ошибку, что такой кадр не найден. И если я непосредственно запускаю свой код, нажимая на кнопку, я получаю ошибку: - Невозможно найти элемент: // * [@ id = 'dutch_popupBtn']

HTML-код: -

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

Мой код: -

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

Ошибка: -

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

Может ли кто-нибудь помочь мне нажать кнопку Разместить ставку. Это было бы очень полезно.

1 Ответ

0 голосов
/ 29 апреля 2018

Согласно HTML, которым вы поделились, и ваш код пытается, я не вижу ни фрейма , представленного name / id как active_auctions , но чтобы найти элемент с id как dutch_popupBtn вам нужно вызвать WebDriverWait следующим образом:

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

Обновление

Согласно вашему обновлению комментария, вы обнаружите, что фокусируется на элементе, но не нажимая , вы можете использовать метод executeScript() следующим образом:

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