ariya / phantomjs

Scriptable Headless Browser
http://phantomjs.org
BSD 3-Clause "New" or "Revised" License
29.48k stars 5.76k forks source link

PhantomJS 2.1 unable to find element with xpath #14987

Closed mysoundmagic closed 6 years ago

mysoundmagic commented 7 years ago

PhantomJS 2.1 Ubuntu 16.04 Selenium WebDriver 3.3.1

PhantomJS always error :

org.openqa.selenium.NoSuchElementException: {"errorMessage":"Unable to find element with xpath '//form[@id='checkoutBooking']/div[4]/div[2]/div/div/div[2]/table/tbody/tr/td/table/tbody/tr/td/img'"

and update :

[ERROR - 2017-05-12T10:37:43.921Z] WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1494585463909

phantomjs://platform/console++.js:263 in error [ERROR - 2017-05-12T10:37:44.620Z] WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1494585464594

phantomjs://platform/console++.js:263 in error

this is part of my code which caused error only when i use phantomJS :

Setup for PhantomJS :

`     dCaps = new DesiredCapabilities();
      dCaps.setJavascriptEnabled(true);
      Src = new File("driver_linux/phantomjs");
      System.setProperty("phantomjs.binary.path", Src.getAbsolutePath());
      driver = new PhantomJSDriver(dCaps);

      Dimension d = new Dimension(1000, 800);
      driver.manage().window().setSize(d);`
WebElement bagasi_button_depart = driver.findElement(By.xpath("//*[@id='ssrSummary-departureFlight-0']/a"));
WebElement bagasi_button_return = driver.findElement(By.xpath("//*[@id='ssrSummary-returnFlight-0']/a"));

`if (driver.findElement(imgOut).isDisplayed()) {
            WebElement getLogo = driver.findElement(imgOut);
            String crlogo = getLogo.getAttribute("src");
            crlogo = crlogo.replace("https://phpssl.nusadev.com/static/img/front/V2/icon-flight/", "");
            crlogo = crlogo.replace("https://ssl.nusatrip.com/static/img/front/V2/icon-flight/", "");
            crlogo = crlogo.replace("http://bo.nusaprod.com/static/img/front/V2/icon-flight/", "");
            CRpicFliTabOut = 1;
            System.out.println("Airplane Logo Displayed");
            System.out.println("Checkout Review Airplane Image : " + crlogo);

            if (picFliTabOut == CRpicFliTabOut) {
                System.out.println("Both Logo Displayed");
            } else {
                System.out.println("one of logo not displayed");
            }

        } else {
            System.out.println("Airplane Logo Not Found");
        }`

i think WebElement & isDisplayed not work with phantomJS 2.1. any ideas ?

NavyCoat commented 7 years ago

Sadly, Also I've got a lot of problem with sessions and locating by text or xpath in current version of phatnomJS.

mysoundmagic commented 7 years ago

yes, me too @NavyCoat and i think PhantomJS not work too with some function in my page_factory

jesg commented 7 years ago

@mysoundmagic have you tried the up to date version of ghostdriver? i'll take a look if you can provide some html that i can use to reproduce the issue.

mysoundmagic commented 7 years ago

I'm sorry for late respond @jesg is PhantomJS 2.1 not use updated ghostdriver ? i don't know how to use it if use it separately. here the html :

<div class="padding10 clearfix">
            <div class="f-rev-sum_wrapper nFlightContainer">
                <!-- start flight info loop -->

                                                                                                                                                                                                                                <input type="hidden" id="searchParams-0" value="CGKDPS2017060120170617100">
                                                                                                                                                                                                                                                                                                                                    <div class="nFlightHeader rounded5top clearfix" style="padding-bottom:3px;">
                                    <div class="hdetName left padding5" style="text-transform:uppercase;">
                                                                                                                                                                                                                                    <input type="hidden" name="flightDepartureDate-0" value="20170601151000">
                                                                                        <table height="17" leftmargin="0" topmargin="0" cell-padding="0" cell-spacing="0" style="height:17px;" class="nusaDateStyle left">
                                                <tbody><tr>
                                                    <td class="daystyle" valign="bottom">
                                                        <span class="dayName">Thu</span>
                                                    </td>
                                                    <td rowspan="2" style="width: 3px;"></td>
                                                    <td class="datestyle" valign="bottom" rowspan="2">
                                                        <span class="day">1</span>
                                                    </td>
                                                    <td rowspan="2" style="width: 8px;"></td>
                                                    <td valign="bottom" rowspan="2" style="font-size:18px; text-transform: none;">Departing Flight                                                        -
                                                        <div class="nFlightDes" style="display:inline-block;">
                                                            Jakarta
                                                            <span>to</span> Denpasar
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="monthstyle" valign="bottom">
                                                        <span class="month">Jun</span>
                                                    </td>
                                                </tr>
                                            </tbody></table>
                                            <br clear="all">
                                                                            </div>
                                </div>
                                <div class="nFlightContent colspan12">
                                    <table class="tCenter" width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tbody><tr>
                                            <td class="marketingAirline">
                                                <table width="95px" border="0" cellspacing="0" cellpadding="0">
                                                    <tbody><tr>
                                                        <td>
                                                                                                                            <img src="https://phpssl.nusadev.com/static/img/front/V2/icon-flight/SJ.png" onerror="imgError(this)" style="height: 45px; margin-top:5px;">

                                                                <div class="maName" style="color: #444;">Focus Air</div>

                                                        </td>
                                                    </tr>
                                                </tbody></table>
                                            </td>
                                            <td valign="top">
                                                <table width="824px" border="0" cellspacing="0" cellpadding="0">
                                                    <tbody><tr>
                                                        <td style="background:#fdfdfd;border-left:1px solid #fff;">
                                                            <table width="823px" border="0" cellspacing="0" cellpadding="0">
                                                                <tbody><tr style="height:25px; border-bottom: 1px solid #e1e0e0;">
                                                                    <td width="65px">Airline</td>
                                                                    <td width="60px">Flight</td>
                                                                    <td width="250px">Departure</td>
                                                                    <td width="250px">Arrival</td>
                                                                    <td width="198px">Price</td>
                                                                </tr>
                                                            </tbody></table>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="border-left:1px solid #fff;">
                                                            <div class="left hControl_depart" style="width:624px; border-right:1px solid #cdd7dc;">

                                                                                                                                        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="content_desc-list" style="background:#fafafa;">
                                                                        <tbody><tr>
                                                                            <td width="65px">

                                                                                <img src="https://phpssl.nusadev.com/static/img/front/V2/icon-flight/SJ.png" onerror="imgError(this)" width="30" height="30"><br>

                                                                                <p class="opAirline" style="color: #444;">Focus Air</p>
                                                                            </td>
                                                                            <td width="60px">SJ260</td>
                                                                            <td width="250px">                                                                                     15:10, 1 Jun 2017
                                                                                    <br>
                                                                                                                                                                <strong>Jakarta  </strong> <span style="color:#444;">
                                                                                         (CGK : Soekarno Hatta) </span>
                                                                            </td>
                                                                            <td width="250px">                                                                                     18:00, 1 Jun 2017
                                                                                    <br>
                                                                                                                                                                <strong>Denpasar  </strong> <span style="color:#444;">
                                                                                        (DPS : Ngurah Rai Intl.) </span>
                                                                            </td>
                                                                                                                                                    </tr>
                                                                                                                                            </tbody></table>
                                                                                                                                                                                            </div>
                                                            <div class="left hControl_depart" style="width:198px;">
                                                                <table class="priceColumn" width="100%" border="0" cellspacing="0" cellpadding="0" style="height: 48px;">
                                                                    <tbody><tr>
                                                                        <td class="nFlightPrice" valign="center" style="border-bottom: 1px solid #e1e0e0 !important;border-top: 1px solid #f9fbfd;border-left:1px solid #f9fbfd;">
                                                                            <span id="price_0_dep" style="display: block;">IDR 582.824</span>
                                                                            <img id="priceLoader_0_dep" src="https://phpssl.nusadev.com/static/img/front/V2/dot-H15.gif" style="display: none;">
                                                                        </td>
                                                                    </tr>
                                                                </tbody></table>
                                                            </div>
                                                                                                                                                                                            <div class="_flConPriceDesc martop5 italic rounded5 hide">
                                                                    <b class="marlet5">Price info:</b>
                                                                                                                                                                                                                                                                            </div>
                                                                                                                    </td>
                                                    </tr>
                                                </tbody></table>
                                            </td>
                                        </tr>
                                    </tbody></table>
                                </div>

                                <div class="nFlightExtraInfo colspan12">
                                    <div class="padding5">
                                        <table width="100%" cellspacing="0" cellpadding="0">
                                            <tbody><tr>
                                                <td id="fExtraDepInfo" style="text-transform:uppercase;">
                                                    <span class="icon-breakfast icon left "></span>
                                                    <span class="icon-tax icon left "></span>

                                                    <div class="hide" id="summary-dep-baggage-wrapper-0" style="display: block;">
                                                        <span class="icon-suitcase icon left marlet10"></span>

                                                        <div id="summary-dep-info" class="left hide" style="color: rgb(68, 68, 68); display: block;">Check-in luggage: <span id="summary-dep-baggage-0">20</span>&nbsp;<span id="summary-dep-baggage-type-0">kg</span>&nbsp;<span>-</span>&nbsp;<span style="text-transform:uppercase; color: #444;">Class                                                                : Economy</span>
                                                        </div>
                                                    </div>
                                                </td>
                                                <td id="fDepClass" class="hide" style="text-transform:uppercase; color: #444;">Class                                                    : Economy</td>

                                                <td class="tRight" style="max-width:330px">
                                                    <div id="ssrSummary-departureFlight-0" class="ssrSummary-0 addBaggContainer right clearfix" style="display:none;">
                                                        <div class="addBaggInfo">
                                                            <table cellpadding="0" cellspacing="0" class="">
                                                                <tbody>
                                                                <tr id="ssrSummary1-departureFlight-0">
                                                                    <td class="ssr-type">Baggage                                                                        :&nbsp;</td>
                                                                                                                                            <td class="ssr-item wid25mid">
                                                                            -
                                                                        </td>

                                                                </tr>
                                                                <tr id="ssrSummary2-departureFlight-0">
                                                                    <td class="ssr-type">Sport Equipment                                                                        :&nbsp;</td>
                                                                                                                                            <td class="ssr-item wid25mid">
                                                                            -
                                                                        </td>

                                                                </tr>
                                                                <tr id="ssrSummary3-departureFlight-0">
                                                                    <td class="ssr-type">Tigerconnect                                                                        :&nbsp;</td>
                                                                                                                                            <td class="ssr-item wid25mid">
                                                                            -
                                                                        </td>

                                                                </tr>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                        <a href="javascript:void(0)" data-reveal-id="flightLuggageContainer-0" data-animationspeed="400" class="addBaggBTN _flightExtra-ib-0" style="min-height: 18px; height: 6px; line-height: 6px;" ref="Depart-0">
                                                            <span class="plus-icon"></span>
                                                            add / modify                                                        </a>
                                                    </div>
                                                </td>
                                            </tr>
                                        </tbody></table>
                                    </div>
                                </div>
                                                                            <div class="colspan12 marbot10"></div>
                                                    <div class="nFlightContainer colspan12">
                                <div class="nFlightHeader rounded5top clearfix" style="padding-bottom:3px;">
                                    <div class="hdetName left padding5" style="text-transform:uppercase;">
                                                                                    <table height="17" leftmargin="0" topmargin="0" cell-padding="0" cell-spacing="0" style="height:17px;" class="nusaDateStyle left">
                                                <tbody><tr>
                                                    <td class="daystyle" valign="bottom">
                                                        <span class="dayName">Sat</span>
                                                    </td>
                                                    <td rowspan="2" style="width: 3px;"></td>
                                                    <td class="datestyle" valign="bottom" rowspan="2">
                                                        <span class="day">17</span>
                                                    </td>
                                                    <td rowspan="2" style="width: 8px;"></td>
                                                    <td valign="bottom" rowspan="2" style="font-size:18px; text-transform: none;">Returning Flight                                                        -
                                                        <div class="nFlightDes" style="display:inline-block;">
                                                            Denpasar
                                                            <span>to</span> Jakarta
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="monthstyle" valign="bottom">
                                                        <span class="month">Jun</span>
                                                    </td>
                                                </tr>
                                            </tbody></table>
                                            <br clear="all">
                                                                            </div>
                                </div>
                                <div class="nFlightContent colspan12">
                                    <table class="tCenter" width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tbody><tr>
                                            <td class="marketingAirline">
                                                <table width="95px" border="0" cellspacing="0" cellpadding="0">
                                                    <tbody><tr>
                                                        <td>

                                                                <img src="https://phpssl.nusadev.com/static/img/front/V2/icon-flight/SJ.png" onerror="imgError(this)" style="height: 45px; margin-top:5px;">
                                                                <div class="maName" style="color:#444;">Focus Air</div>

                                                        </td>
                                                    </tr>
                                                </tbody></table>
                                            </td>
                                            <td valign="top">
                                                <table width="824px" border="0" cellspacing="0" cellpadding="0">
                                                    <tbody><tr>
                                                        <td style="background:#fdfdfd;border-left:1px solid #fff;">
                                                            <table width="823px" border="0" cellspacing="0" cellpadding="0">
                                                                <tbody><tr style="height:25px; border-bottom: 1px solid #e1e0e0;">
                                                                    <td width="65px">Airline</td>
                                                                    <td width="60px">Flight</td>
                                                                    <td width="250px">Departure</td>
                                                                    <td width="250px">Arrival</td>
                                                                    <td width="198px">Price</td>
                                                                </tr>
                                                            </tbody></table>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="border-left:1px solid #fff;">
                                                            <div class="left hControl_depart" style="width:624px; border-right:1px solid #cdd7dc;">

                                                                                                                                        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="content_desc-list" style="background:#fafafa;">
                                                                        <tbody><tr>
                                                                            <td width="65px" "="">

                                                                            <img src="https://phpssl.nusadev.com/static/img/front/V2/icon-flight/SJ.png" onerror="imgError(this)" width="30" height="30"><br>

                                                                            <p class="opAirline" style="color: #444;">Focus Air</p>
                                                                            </td>
                                                                            <td width="60px">SJ261</td>
                                                                            <td width="250px">                                                                                     19:00, 17 Jun 2017
                                                                                    <br>
                                                                                                                                                                <strong>Denpasar  </strong> <span style="color:#444;">
                                                                                         (DPS : Ngurah Rai Intl.) </span>
                                                                            </td>
                                                                            <td width="250px">                                                                                     19:40, 17 Jun 2017
                                                                                    <br>
                                                                                                                                                                <strong>Jakarta  </strong> <span style="color:#444;">
                                                                                         (CGK : Soekarno Hatta) </span>
                                                                            </td>
                                                                                                                                                    </tr>
                                                                                                                                            </tbody></table>
                                                                                                                                                                                            </div>
                                                            <div class="left hControl_return" style="width:198px;">
                                                                <table class="priceColumn" width="100%" border="0" cellspacing="0" cellpadding="0" ;="" style="height: 48px;">
                                                                    <tbody><tr>
                                                                        <td class="nFlightPrice" valign="center" style="border-bottom: 1px solid #e1e0e0 !important;border-top: 1px solid #f9fbfd;border-left:1px solid #f9fbfd;">
                                                                            <span id="price_0_ret" style="display: block;">IDR 624.785</span>
                                                                            <img id="priceLoader_0_ret" src="https://phpssl.nusadev.com/static/img/front/V2/dot-H15.gif" style="display: none;">
                                                                        </td>
                                                                    </tr>
                                                                </tbody></table>
                                                            </div>
                                                                                                                                                                                            <div class="_flConPriceDesc martop5 italic rounded5 hide">
                                                                    <b class="marlet5">Price info:</b>
                                                                                                                                                                                                                                                                            </div>
                                                                                                                    </td>
                                                    </tr>
                                                </tbody></table>
                                            </td>
                                        </tr>
                                    </tbody></table>
                                </div>
                                <div class="nFlightExtraInfo colspan12">
                                    <div class="padding5">
                                        <table width="100%" cellspacing="0" cellpadding="0">
                                            <tbody><tr>
                                                <td id="fExtraRetInfo" style="text-transform:uppercase;">
                                                <span class="icon-breakfast icon left "></span>
                                                <span class="icon-tax icon left "></span>

                                                <div class="hide" id="summary-ret-baggage-wrapper-0" style="display: block;">
                                                    <span class="icon-suitcase icon left marlet10"></span>

                                                    <div id="summary-ret-info" class="left hide" style="color: rgb(68, 68, 68); display: block;">Check-in luggage: <span id="summary-ret-baggage-0">20</span>&nbsp;<span id="summary-ret-baggage-type-0">kg</span>&nbsp;<span>-</span>&nbsp;<span style="text-transform:uppercase; color: #444;">Class                                                            : Economy</span>
                                                    </div>
                                                </div>
                                                </td>
                                                <td id="fRetClass" class="hide" style="text-transform:uppercase; color:#444;">Class                                                    : Economy</td>

                                                <td class="tRight" style="max-width:330px">
                                                    <div id="ssrSummary-returnFlight-0" class="ssrSummary-0 addBaggContainer right clearfix" style="display:none;">
                                                        <div class="addBaggInfo">
                                                            <table cellpadding="0" cellspacing="0" class="">
                                                                <tbody>
                                                                <tr id="ssrSummary1-returnFlight-0">
                                                                    <td class="ssr-type">Baggage                                                                        :&nbsp;</td>
                                                                                                                                            <td class="ssr-item wid25mid">
                                                                            <span class="empty pax-icon"></span><span class="empty pax-bag">-</span>
                                                                        </td>

                                                                </tr>
                                                                <tr id="ssrSummary2-returnFlight-0">
                                                                    <td class="ssr-type">Sport Equipment                                                                        :&nbsp;</td>
                                                                                                                                            <td class="ssr-item wid25mid">
                                                                            -
                                                                        </td>

                                                                </tr>
                                                                <tr id="ssrSummary3-returnFlight-0">
                                                                    <td class="ssr-type">Tigerconnect                                                                        :&nbsp;</td>
                                                                                                                                            <td class="ssr-item wid25mid">
                                                                            -
                                                                        </td>

                                                                </tr>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                        <a href="javascript:void(0)" data-reveal-id="flightLuggageContainer-0" data-animationspeed="400" class="addBaggBTN _flightExtra-ib-0" style="min-height: 18px; height: 6px; line-height: 6px;" ref="Return-0">
                                                            <span class="plus-icon"></span>
                                                            add / modify                                                        </a>
                                                    </div>
                                                </td>
                                            </tr>
                                        </tbody></table>
                                    </div>
                                </div>
                            </div>

                <div class="nFlightSum colspan12">
                    <table width="100%" cellspacing="0" cellpadding="0">
                        <tbody>
                        <tr>
                            <td width="195px" class="backBTN" valign="center">
                                <a href="http://phptest1.nusadev.com/checkout/postbooking?search_id=_JKTDPS2017060120170617100" style="color: #444;"><span class="back-icon"></span>Back to Flight Search</a>
                            </td>

                            <td id="label_validate_0" width="465px" style="padding: 0px 10px; background: rgb(13, 122, 180); color: rgb(255, 255, 255); display: none;">
                                Validate flight availability and price                            </td>
                            <td id="Tlabel_validate_0" class="tCenter" style="padding: 0px 10px; background: rgb(13, 122, 180); color: rgb(255, 255, 255); font-size: 12px; width: 30px; display: none;">
                            </td>
                            <td id="Plabel_validate_0" class="tCenter" style="padding: 0px 10px; background: rgb(13, 122, 180); color: rgb(255, 255, 255); border-radius: 0px 5px 5px 0px; display: none;" width="198px">
                                <img src="https://phpssl.nusadev.com/static/img/front/V3/checkout/l-blue.gif" width="165" height="15" style="margin-top: 5px; display: inline-block;"></td>

                            <td id="flightInfoNotExists_0" width="465px" style="padding:0 10px; background:#0d7ab4; color:#FFF; display: none;">
                                This flight not available anymore. Please <a style="color: orange" href="http://phptest1.nusadev.com/checkout/postbooking?search_id=_JKTDPS2017060120170617100"><strong>search again</strong></a>
                            </td>
                            <td id="TflightInfoNotExists_0" class="tCenter" style="display:none; padding:0 10px; background:#0d7ab4; color:#FFF; font-size:12px; width: 30px;">
                            </td>
                            <td id="PflightInfoNotExists_0" class="tCenter" style="display:none; padding:0 10px; background:#0d7ab4; color:#FFF; -moz-border-radius: 0 5px 5px 0;-webkit-border-radius: 0 5px 5px 0; border-radius: 0 5px 5px 0;" width="198px"><strong style="font-size:16px; margin-top:4px; display:inline-block;">
                                </strong></td>

                            <td id="info_total_0" width="465px" style="padding: 0px 10px; background: rgb(13, 122, 180); color: rgb(255, 255, 255);">
                                Total price for&nbsp;
                                                                    1 adult                                                                                                                                &nbsp;including taxes                                </td>
                            <td id="label_total_0" class="tCenter" style="padding: 0px 10px; background: rgb(13, 122, 180); color: rgb(255, 255, 255); font-size: 12px;">

                            </td><td id="price_total_0" class="tCenter" style="font-size: 16px; margin-top: 4px; padding: 0px; background: rgb(13, 122, 180); color: rgb(255, 255, 255); border-radius: 0px 5px 5px 0px; font-weight: 700 !important;" width="198px">IDR 1.207.609</td>

                        </tr>
                        </tbody>
                    </table>
                </div>
                <small class="infoValidate" id="flightInfoUpdated_0" style="display: block;">
                    This flight has been updated.  <span id="flightInfoUpdatedMark_0" class="cleanSpan" style="display: inline;"></span> <span id="flightInfoUpdatedValue_0" class="cleanSpan" style="display: inline;">+ <span class="currencyText">IDR</span> 1</span>
                </small>
            </div>
            <div class="clearfix"></div>
            <!-- end flight info loop -->
        </div>
jesg commented 7 years ago

@mysoundmagic there are no elements that match //form[@id='checkoutBooking']/div[4]/div[2]/div/div/div[2]/table/tbody/tr/td/table/tbody/tr/td/img in the html you provided.

mysoundmagic commented 7 years ago

@jesg i don't have source from html file. I copied then paste it from inspect Element chrome

this xpath

//form[@id='checkoutBooking']/div[4]/div[2]/div/div/div[2]/table/tbody/tr/td/table/tbody/tr/

from this html code

<table width="95px" border="0" cellspacing="0" cellpadding="0">
 <tbody><tr>
  <td>
    <img src="https://phpssl.nusadev.com/static/img/front/V2/icon-flight/SJ.png" onerror="imgError(this)" style="height: 45px; margin-top:5px;">
      <div class="maName" style="color:#444;">Focus Air</div>
  </td>
 </tr>
 </tbody></table>

or you can try in link route to nusatrip.com/checkout/review, you can inspect element on image of marketing airline

qwertyI commented 7 years ago

I think you can print the page_source. Maybe the page source is different between Chrome and PhantomJS.

mysoundmagic commented 7 years ago

update after many hours for investigate about this issue. element can't be found because not moved to the next page. I think it caused can not execute this (i've try below codes and not work) : ((JavascriptExecutor) driver).executeScript("arguments[0].click();", driver.findElement(By.xpath("//a[@id='btnContinue']")));

or

driver.findElement(//a[@id='btnContinue']).click()

HTML : <a id="btnContinue" class="right btn martop10 green">Continue Booking</a>

kensoh commented 7 years ago

@mysoundmagic I'm a CasperJS user for couple of years, now browsing through open issues on CasperJS/PhantomJS. Isn't it something like this? If using web inspector on that page the web element exists and only 1 occurrence then a simple referencing should work. If you want to save time and simplify. Not always necessary to //a or specify the type of element.

driver.FindElement(By.XPath('//*[@id="btnContinue"]')).Click();

@jesg I think I saw you somewhere on Mastodon lol or on some Mastodon issues.

mysoundmagic commented 7 years ago

@kensoh, i'm so sorry for my bad english. Thank you for your answer. I've try with driver.FindElement(By.XPath('//*[@id="btnContinue"]')).Click(); because before i was used with //a, i've try with //* . still no luck with phantomJS or headless browser e.g new update of chrome with headless configuration. currently, i'm still stuck with only that element.

kensoh commented 7 years ago

I see.. No probs @mysoundmagic .. Another way if possible, is to share your full PhantomJS script, so that we can try to run it and debug the error. But if there is some private password then not good idea to share here. Oh you are from Jakarta, I have visited Jakarta many times in my previous job. I stayed at Hotel Mulia. Nice live band every night :)

mysoundmagic commented 7 years ago

@kensoh i'm not use javascript like the PhantomJS documentation, i'm use selenium java with phantomJS configuration for headless testing. i'll attach my script when available in office. You stayed in five stars hotel in jakarta, how lucky you. you should visit Raja Ampat for holidays, it's a wonderful place to visit :))

kensoh commented 7 years ago

Oh I see.. I used to work on Selenium Java with Chrome/Firefox. In any case, you can try to share your script here (but with no sensitive information such as real user id and password). May I can see something or jesg can see something to add.

Thank you haha, I stayed in that job for almost 5 years, travel a lot but low pay. Thanks also for recommendation! I just saw the beautiful photos of Raja Ampat :)

mysoundmagic commented 7 years ago

@kensoh i'm so sorry for late respond and i attach some script. note : i have to remove some part of code with credential information, i hope there is no error. :))

You're welcome. :D

script.zip

kensoh commented 7 years ago

@mysoundmagic it is complex scenario no wonder. I've looked through the code and saw the website. From above you are saying driver.findElement(By.xpath("//*[@id='btnContinue']")).click(); cannot work and the original code was calling JavaScript code directly.

Is it the script is passed on to you by previous team member? Not sure how easy is it to change to some visible web browser driver and then run this test in phantomJS_checkIcons.java. So that just before clicking that continue you can see if the button is there. Or if using PhantomJS through Ghostdriver you can print the page source to check the html.

As @qwertyI pointed out, sometimes PhantomJS (actually often) renders differently from real browsers. Increasingly will be I guess, as website owners want to prevent access by automated or invisible browsers. So maybe when you visit the website using normal browser you see the button but using PhantomJS it may not be there.

Another way if I were to approach this situation is I will use a general purpose web automation tool I made using CasperJS/PhantomJS. It lets me rapidly prototype with features such as live mode, Chrome extension, and simple use. But it's more for non-developers. I don't know if it makes sense for developers to pick up something like this. Probably better to just print page source and debug from there. http://github.com/tebelorg/TagUI

mysoundmagic commented 7 years ago

@kensoh this script never passed on previous team member, because this first time using selenium webdriver in team. Thank you for suggestion. i think i will back to use chrome or firefox with Xvfb, the fastest way i can provide.

kensoh commented 7 years ago

@mysoundmagic I see.. It is a complicated test scenario, good luck!

Yes that is a common solution, in fact the creator of PhantomJS Ariya discourage using PhantomJS for testing, because real users using other browsers such as Chrome, Safari etc. And it is not 100% similar.

In any case, maybe you can leave this thread open and add on to it if there's any news.

mysoundmagic commented 7 years ago

ok, thank you so much @kensoh

wcdeich4 commented 6 years ago

This works for me: System.setProperty("phantomjs.binary.path", seleniumBrowserDriverPath); DesiredCapabilities caps = new DesiredCapabilities(); caps.setJavascriptEnabled(true); caps.setCapability("locationContextEnabled", true); caps.setCapability("applicationCacheEnabled", true); caps.setCapability("browserConnectionEnabled", true); caps.setCapability("localToRemoteUrlAccessEnabled", true); caps.setCapability("locationContextEnabled", true); caps.setCapability("takesScreenshot", true); caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, seleniumBrowserDriverPath); PhantomJSDriver driver = new PhantomJSDriver(caps);