2017-11-09 17 views
-1

から選択することができません、私はサポートを強調表示し、セレンwebdriverをを使用して、ドロップダウンからドキュメントを選択しようとしています。Webページ上のリンクを強調表示してから<em>www.netiq.com</em>リンクを開いた後、ドロップダウン

HTMLコード:

<ul> 
<li id="nav_solutions" class="large"> 
<li id="nav_products" class="large"> 
<li id="nav_industry" class=""> 
<li id="nav_service" class="active hover"> 
<a id="hdr_support_main" href="/services/" onclick="ga('send', 'event', 'header', 'support', 'main');" data-di-id="#hdr_support_main"> 
<strong>Support</strong> 
<i class="downarrow"/> 
<i class="arrow"/> 
</a> 
<div style="display: block;"> 
<ul> 
<li> 
<li> 
<li> 
<li> 
<li> 
<li> 
<a id="hdr_support_documentation" href="https://www.netiq.com/documentation/" onclick="ga('send', 'event', 'header', 'support', 'documentation');" data-di-id="#hdr_support_documentation"> 
Documentation 
<i class="arrow"/> 
</a> 
</li> 

は、私がこれを書いてみました:

from selenium import webdriver 
# from selenium.webdriver.common.keys import Keys 
from selenium.webdriver.support.ui import Select 
import time 

driver = webdriver.Firefox() 
driver.get("https://www.netiq.com/") 
time.sleep(5) 
# select=Select(driver.find_element_by_xpath(".//*[@id='hdr_support_main']")) 
# driver.find_element_by_xpath(".//*[@id='hdr_support_documentation']").click() 

select = Select(driver.find_element_by_id("hdr_support_main")) 

select.select_by_visible_text("hdr_support_documentation") 

エラー:メッセージ:唯一の選択ではない

助けてくださいに、要素上で動作します。

+0

実際、完全なエラーメッセージを投稿してください。問題は、エラーメッセージに記載されているように、 'SELECT'要素ではない要素に対して' Select'クラスを使用していることです。それはただのように見えます。これを解決するには、ドロップダウン要素をクリックし、公開リストから目的のオプションをクリックする必要があります。他のHTMLと同様に、Seleniumは可視要素とのみ対話するため、ドロップダウンをクリックしてオプションを公開する必要があります。 – JeffC

+0

エラーメッセージ全体が表示されていない。 ここにあります: selenium.common.exceptions.UnexpectedTagNameException:メッセージ:選択は –

答えて

0

あなたが、「サポート」の要素にカーソルを移動する必要が前に:

ActionChains(driver).move_to_element(support).perform() 

全体コード:

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

driver.get("https://www.netiq.com/") 
support= driver.find_element_by_xpath("//*[@id='nav_service']") 
ActionChains(driver).move_to_element(support).perform() 

wait = WebDriverWait(driver, 20) 
docButton= wait.until(EC.element_to_be_clickable((By.XPATH,"//*[@id='hdr_support_documentation']"))) 

docButton.click() 
+0