2016-07-12 4 views
0

JavaとSelenium WebDriverを使い慣れています。 WebDriverの使い方を知るために、私はエミレーツウェブサイトのフライト予約プロセスを自動化することに決めました。私は問題を抱えていましたが、今私は本当に立ち往生しています。私がフライトを選択する前に、フライトを選択する前に、先進的な旅の第2脚を決めて「ファーストクラス」の旅をすると、このプロセスを自動化する方法を理解することはできません。大人の乗客の数。私はここにhtmlを含めていないが、リストの中の要素を調べるときに見つけることができる。SelectとWebElementが機能しない場合に、リストを開いてSelenium WebDriverでオプションを選択するには

ので動作するコードはこれです:

WebDriver driver = new ChromeDriver(); 

    // This opens the browser on the Emirates homepage 
    driver.get("http://www.emirates.com/uk/english/"); 

    // Opening main menu item "Book" 
    driver.findElement(By.xpath("//li[@id='book']/a/span")).click(); 

    // For the second leg of the flight, I wish to travel first class > 
    // therefore I open the drop down and select "First 
    driver.findElement(By.id("ctl00_c_CtWNW_flightClass1_chosen")).click(); 

しかし、私は「ファーストクラス」を選択すると、これは私のように旅行したいクラスとして表示され、を進めてきたどのようにうまくいかないことができます予約。誰も助けることができますか?

これは、(XPathは表示された)FirePathから取られる:

<li id="option_id_ctl00_c_CtWNW_flightClass1_chosen_2" class="active-result" style="" data-option-array-index="2" text="First Class" role="option" aria-selected="false" tabindex="-1"> 

私は右のコンボボックス

そしてDIVからHTMLからのファーストクラスをクリックすると:

<div id="ctl00_c_CtWNW_flightClass1_chosen" title="Select your preferred cabin class for your inbound flight. - Selected: First Class" style="width: 100%;" class="chosen-container chosen-container-single chosen-container-single-nosearch"><a aria-expanded="false" title="Select your preferred cabin class for your inbound flight. - Selected: First Class" class="chosen-single" role="combobox" tabindex="0"><em aria-live="polite" class="visually-hidden">Selected: First Class</em><span class="cabin-class_3" aria-hidden="true">First Class</span><div><strong></strong></div></a><div class="chosen-drop" aria-hidden="true"><div class="chosen-search" aria-hidden="true"><label class="label-hidden" for="chosenLabel1">Label</label><input aria-activedescendant="option_id_ctl00_c_CtWNW_flightClass1_chosen_0" readonly="" id="chosenLabel1" autocomplete="off" placeholder="Input a value to search" style="display: none;" type="text"></div><ul class="chosen-results" tabindex="-1"><li tabindex="-1" aria-selected="false" role="option" text="Economy Class" id="option_id_ctl00_c_CtWNW_flightClass1_chosen_0" data-option-array-index="0" style="" class="active-result"><span style="display: inline;float:none;">Economy Class</span></li><li aria-selected="false" role="option" text="Business Class" id="option_id_ctl00_c_CtWNW_flightClass1_chosen_1" data-option-array-index="1" style="" class="active-result"><span style="display: inline;float:none;">Business Class</span></li><li tabindex="-1" aria-selected="true" role="option" text="First Class" id="option_id_ctl00_c_CtWNW_flightClass1_chosen_2" data-option-array-index="2" style="" class="active-result result-selected"><span style="display: inline;float:none;">First Class</span></li></ul></div></div> 
<a aria-expanded="false" title="Select your preferred cabin class for your inbound flight. - Selected: First Class" class="chosen-single" role="combobox" tabindex="0"><em aria-live="polite" class="visually-hidden">Selected: First Class</em><span class="cabin-class_3" aria-hidden="true">First Class</span><div><strong></strong></div></a> 
<em aria-live="polite" class="visually-hidden">Selected: First Class</em> 
<span class="cabin-class_3" aria-hidden="true">First Class</span> 

The image shows the output from Firepath after clicking on First Class, in the console

+0

あなたは選択したいhtmlのスニペットを入力してください。 – Abaddon666

+0

投稿するhtml(dom)は役に立ちます –

+0

こんにちはAbaddon666、私はコードの適切な領域であると思うものについてXPathを含めました – ScrimWizard

答えて

0

試用:

// Opening main menu item "Book" 
WebDriverWait wait = new WebDriverWait(driver, 10); 
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//li[@id='book']/a/span"))); 
element.click(); 

// For the second leg of the flight, I wish to travel first class > 
// therefore I open the drop down and select "First 


WebDriverWait wait = new WebDriverWait(driver, 10); 
WebElement ele = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("li#ctl00_c_CtWNW_flightClass1_chosen"))); 
ele.click(); 

+0

Eclipseのコンソールでベクトルスマッシュ例外が発生し続ける: 'ベクトルスマッシュ保護が有効になっています。 スレッド "main"の例外org.openqa.selenium.TimeoutException:要素がクリック可能になるのを待ってから10秒後にタイムアウトしました:By.cssSelector:li#ctl00_c_CtWNW_flightClass1_chosen 原因:org.openqa.selenium.NoSuchElementException:そのような要素がありません:要素が見つかりません:{「方法」:「CSSセレクタ」、「セレクタ」:「LI位ctl00_c_CtWNW_flightClass1_chosen」} (セッション情報:クロム= 51.0.2704.103) ' – ScrimWizard

+0

ので、ここでの問題は、この要素セレクタ' Liとなります#ctl00_c_CtWNW_flightClass1_chosen' 'li [text = 'ファーストクラス'] ' –

+0

あなたの助けてくれてありがとうございますが、 – ScrimWizard

関連する問題