2017-08-08 25 views
1

Pythonで特定のページにアクセスするために、セレニウムを使用してスクリプトを作成しました。そこに到達するには5つのステップがあります。最初に私のブラウザは「アドレスで検索」ボタンをクリックし、ボックスに「ストリート名」と対応するボックスに「ストリートアドレス」と入力し、検索ボタンをクリックしてターゲットページに移動する必要があります。しかし、「アドレスで検索」ボタンをクリックしている間、最初の試みでエラーが発生します。それに応じて私はそれをしたようだが、私は間違いを犯しているのか分からない。それを調べるために事前に感謝します。 私がしようとしているスクリプト:「アドレスで検索」のボタンは、IDが発見され、その中Pythonセレニウムがボタンをクリックできない

from selenium import webdriver 
from selenium.webdriver.common.by import By 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC  

driver = webdriver.Chrome() 
driver.get("http://hcad.org/quick-search/") 
wait = WebDriverWait(driver, 10) 
driver.find_element_by_id("s_addr").click() 
driver.find_element_by_name('stnum').send_keys('8227') 
driver.find_element_by_name('stname').send_keys('FINDLAY ST') 
driver.find_element_by_link_text("Search").click() 
driver.quit() 

要素:残りのキーワードをボックスに記入する、その中

<tbody><tr> 
<td class="auto-style1"></td> 
<td width="15" align="left" valign="top" class="auto-style1"></td> 
<td width="600" align="left" valign="top" class="auto-style1"> 

<input type="submit" id="s_acct" value="Search By Account">&nbsp; 
<input type="submit" id="s_addr" value="Search By Address">&nbsp; 
<input type="submit" id="s_name" value="Search By Owner Name"><table> 
<form id="search_button" name="search_button" action="/records/QuickSearch.asp" method="post"></form> 

要素を:

<tr align="middle"> 
<td colspan="1">  
<select name="TaxYear">       
<option value="2017">2017</option>    
</select></td>  
<td align="middle"> 
<input name="stnum" size="5" maxlength="5"></td> 
<td align="middle"> 
<input name="stname" maxlength="24"> 
</td><td align="middle"> 
<nobr><input type="submit" value="Search"></nobr> 
</td> 
</tr> 

エラー私は取得しています:

raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: 

答えて

1

iframeが利用可能になるのを待つ必要があります。

... 
wait = WebDriverWait(driver, 10) 
element = wait.until(EC.presence_of_all_elements_located((By.TAG_NAME, 'iframe'))) 
driver.switch_to.frame(driver.find_element_by_tag_name("iframe")) 
driver.find_element_by_id("s_addr").click() 
driver.find_element_by_name('stnum').send_keys('8227') 
driver.find_element_by_name('stname').send_keys('FINDLAY ST') 
... 

また、xpathを使用すると、検索ボタンを選択するより便利な方法のようです。

driver.find_element_by_xpath("//input[@value='Search']").click() 
driver.quit() 
+0

ありがとうございますOluwafemi Sule、あなたの効果的な答えです。私はしばらくの間、iframeを忘れてしまった。それはトリックでした。 – SIM

関連する問題