2014-10-20 30 views
0

我們正在使用此Google API https://developers.google.com/places/documentation/autocomplete,我想自動執行測試用例以選擇特定的地址。Watir-webdrive如何自動執行google地點自動完成功能

<fieldset class="control-group"> 
<a class="button small grey search-again" style="display: none;" href="#"> Erneut versuchen </a> 
<input class="address-search" type="text" data-required="true" placeholder="Geben Sie Ihre Adresse ein" autocomplete="off"> 

這是需要填寫的文本字段。 我試圖

@address_page.address_line1 = line1 
text_field(:address, :class => 'address-search') 

,但它只是打開的建議名單,並沒有選擇一個我輸入了,我有這個錯誤

Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotVisibleError) 
     [remote server] file:///var/folders/zg/1303qv_56kjc0r43rpb9h0b40000gp/T/webdriver-profile20141020-26884-1it1xd2/extensions/[email protected]/components/command_processor.js:10816:in `DelayedCommand.prototype.checkPreconditions_' 

如何解決這個螞蟻的建議嗎?

+0

在您輸入文本字段後,您如何從自動完成列表中選擇項目?那是你在哪裏得到可見性異常(即,究竟是哪個命令產生的異常)? – 2014-10-20 16:47:57

+0

這是我無法做到的,我如何才能選擇正在打開的列表中的項目? – fege 2014-10-21 07:57:39

回答

1

當與谷歌自動完成外地工作,你將需要:

  1. 類型的東西到文本字段
  2. 等待的建議出現在列表中。這是爲了避免Watir在加載之前嘗試與建議進行交互的可能性。
  3. 單擊代表建議的div元素之一。

下面是使用谷歌地圖JavaScript API v3示例頁面工作的例子:

# Go to the page 
browser = Watir::Browser.new 
browser.goto('http://code.google.com/apis/maps/documentation/javascript/examples/places-autocomplete.html') 

# For the test page, the places autocomplete is in an iframe 
iframe = browser.div(id: 'gc-content').iframe 

# Get the autocomplete field 
autocomplete = iframe.text_field(id: 'pac-input') 

# Type something into the autocomplete field 
autocomplete.set('Aus') 

# Wait for the list of suggestions to be displayed 
suggestion_menu = iframe.div(class: 'pac-container') 
suggestion_menu.wait_until_present 

# Click one of the suggestions, in this case, we clicked the second suggestion 
suggestion_menu.div(class: 'pac-item', index: 1).click 

# Check that the autocomplete value is updated 
p autocomplete.value 
#=> "Australian Capital Territory, Australia" 

注意,你可能需要調整腳本爲您具體實施。例如,文本字段ID可能不是'pac-input'。然而,一般的概念應該適用於這個和許多其他的自動填充字段。