我有一個代碼,點擊網頁上的一個按鈕,彈出一個menubar
。我想從出現的選項中選擇一個menuitem
,然後click
menuitem
(如果可能);然而,我在路障。Python Selenium從「menubar」中選擇「menuitem」
這裏是代碼的相關部分迄今:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('URL')
Btn = driver.find_element_by_id('gwt-debug-BragBar-otherDropDown')
Btn.click() #this works just fine
MenuItem = driver.find_element_by_id('gwt-uid-463') #I'm stuck on this line
MenuItem.click()
這裏是它的基礎是什麼我寫拋出的錯誤:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element
注:看來該id
因爲這個元素每次頁面加載都會改變(這可能是錯誤的原因)。我試着搜索find_element_by_class_name
,但它有一個複合類名稱,我也一直在那裏得到一個錯誤。
這裏是menubar
的代碼:
<div class="gux-combo gux-dropdown-c" role="menubar" id="gwt-debug-BragBar-otherMenu">
和menuitem
我想:
<div class="gux-combo-item gux-combo-item-has-child" id="gwt-uid-591" role="menuitem" aria-haspopup="true">text</div>
我正在尋找一種方式來選擇menuitem
。謝謝!
感謝您的快速回答,@alecxe!試過了,它完美地完成了這項工作。 – Daniel 2014-11-11 04:45:30