私は選択された運送会社(TNT)にオンライン注文を与えるタスクを自動化するPHP facebook/webdriver 1.4.1とセレニウム3.5のスクリプトをまとめようとしています。は、この機能を実現するための休憩APIを提供していないため、実際には手間をかけずに済ませることができます。セレブのドロップダウンから選択してくださいfacebookから
<ul>
と<li>
の束で生成されたjscriptであるSelectboxを除いて、スクリプトが正常に動作し、目的の値を選択できません。
これは<li>
IDが生成され、自動、およびページ内の他のselectboxesに複製され、私はできない$driver->findElement(WebDriverBy::id('6'))->click();
選択
<td>
\t <select id="latestCollectionTime" name="latestCollectionTime" style="display: none;">
\t \t <option value="" selected="selected">
\t \t \t selecteer...
\t \t </option>
\t \t <option value="2230">
\t \t \t 22:30
\t \t </option>
\t \t <option value="2245">
\t \t \t 22:45
\t \t </option>
\t \t <option value="2300">
\t \t \t 23:00
\t \t </option>
\t \t <option value="2315">
\t \t \t 23:15
\t \t </option>
\t \t <option value="2330">
\t \t \t 23:30
\t \t </option>
\t \t <option value="2345">
\t \t \t 23:45
\t \t </option>
\t </select>
\t <span id="latestCollectionTime-dropdown" class="selectboxit-container">
\t \t <span id="latestCollectionTimeSelectBoxIt" class="selectboxit dropdown-menu" style="" name="latestCollectionTime" tabindex="0" unselectable="on" role="combobox" aria-autocomplete="list" aria-expanded="false"
\t \t aria-owns="latestCollectionTimeSelectBoxItOptions" aria-activedescendant="0" aria-label="" aria-live="assertive">
\t \t \t <i id="latestCollectionTimeSelectBoxItDefaultIcon" class="selectboxit-default-icon selectboxit-option-icon" unselectable="on" style="margin-top: 5.5px;">
\t \t \t </i>
\t \t \t <span id="latestCollectionTimeSelectBoxItText" class="selectboxit-text" unselectable="on" data-val="" style="line-height: 22px; max-width: 88px;">
\t \t \t \t selecteer...
\t \t \t </span>
\t \t \t <span id="latestCollectionTimeSelectBoxItArrowContainer" class="selectboxit-arrow-container" unselectable="on" style="height: 22px;">
\t \t \t \t <i id="latestCollectionTimeSelectBoxItArrow" class="selectboxit-arrow caret" unselectable="on" style="margin-top: 7px;">
\t \t \t \t </i>
\t \t \t </span>
\t \t </span>
\t \t <ul id="latestCollectionTimeSelectBoxItOptions" class="selectboxit-options" tabindex="-1" role="listbox" aria-hidden="true" style="max-height: 198px; top: auto; display: none;">
\t \t \t <li id="0" data-val="" data-disabled="false" class="selectboxit-option selectboxit-option-first" style="" role="option">
\t \t \t \t <a class="selectboxit-option-anchor"><i class="selectboxit-option-icon " style="margin-top: 3.5px;"></i>selecteer...</a>
\t \t \t </li>
\t \t \t <li id="1" data-val="2230" data-disabled="false" class="selectboxit-option" style="" role="option">
\t \t \t \t <a class="selectboxit-option-anchor"><i class="selectboxit-option-icon " style="margin-top: 3.5px;"></i>22:30</a>
\t \t \t </li>
\t \t \t <li id="2" data-val="2245" data-disabled="false" class="selectboxit-option" style="" role="option">
\t \t \t \t <a class="selectboxit-option-anchor"><i class="selectboxit-option-icon " style="margin-top: 3.5px;"></i>22:45</a>
\t \t \t </li>
\t \t \t <li id="3" data-val="2300" data-disabled="false" class="selectboxit-option" style="" role="option">
\t \t \t \t <a class="selectboxit-option-anchor"><i class="selectboxit-option-icon " style="margin-top: 3.5px;"></i>23:00</a>
\t \t \t </li>
\t \t \t <li id="4" data-val="2315" data-disabled="false" class="selectboxit-option" style="" role="option">
\t \t \t \t <a class="selectboxit-option-anchor"><i class="selectboxit-option-icon " style="margin-top: 3.5px;"></i>23:15</a>
\t \t \t </li>
\t \t \t <li id="5" data-val="2330" data-disabled="false" class="selectboxit-option" style="" role="option">
\t \t \t \t <a class="selectboxit-option-anchor"><i class="selectboxit-option-icon " style="margin-top: 3.5px;"></i>23:30</a>
\t \t \t </li>
\t \t \t <li id="6" data-val="2345" data-disabled="false" class="selectboxit-option selectboxit-option-last" style="" role="option">
\t \t \t \t <a class="selectboxit-option-anchor"><i class="selectboxit-option-icon " style="margin-top: 3.5px;"></i>23:45</a>
\t \t \t </li>
\t \t </ul>
\t </span>
</td>
通常の方法では選択できません。
$driver->findElement(WebDriverBy::id('latestCollectionTime'))
->findElement(WebDriverBy::cssSelector("option[value='11']"))
->click();
選択が隠されているのはstyle="display: none;
で、xpathではないためです。
I直接data-val="2330"
ような値を選択できるようにしたいが、同じ<li>
IDとデータ-VAL値を有するが、diferent <span>
と<ul>
IDを持つ他の3 selectboxesであることを考慮して取ることになります。
誰もがこれを手伝ってくれますか? ありがとうございます。
EDIT:たxPath sintaxと正しい方向に私を指しているため、以下の答えで@DANに再び
//make the dropdow list visible.
$driver->findElement(WebDriverBy::id('latestCollectionTimeSelectBoxIt'))->click();
// to click in the desired option.
$driver->findElement(WebDriverBy::xPath('//*[@id = "latestCollectionTimeSelectBoxItOptions"]/li[@data-val = "'.$desired_value.'"]'))->click();
ありがとう:
私はこのようにそれを使用して終了します。
ありがとうございます! 私はこれを次のように使います: '$ driver-> findElement(WebDriverBy :: id( 'latestCollectionTimeSelectBoxIt')) - > click();'をクリックするとドロップドウンが表示され、 '$ driver-> findElement目的のオプションをクリックするには、WebDriverBy :: xPath( '// * [@ id = "latestCollectionTimeSelectBoxItOptions"]/li [@ data-val = "2230"]')) - >クリック(); もう一度、xPath sintaxを使用して、正しい方向にポイントしてくれてありがとう。 – Kuasarx