in selenium xpath and innerHTML



我是硒的新手。我想自动选择我网页上的选项。我正在尝试将select与xpath一起使用。是否可以在没有id的情况下只使用xpath来获取innerHTML?如果是,如何?如果没有,那么如何使用select解决问题。

是的,这是可能的。从这里开始:http://www.w3schools.com/xpath/.

下面是python中的一个快速下拉示例:

from selenium.webdriver import Chrome

SETTINGS_PAGE_URL = 'chrome://settings/browser'
SEARCH_ENGINE_DROPDOWN_ID = 'defaultSearchEngine'
SEARCH_ENGINE_CHOICE_XPATH = '//option[text()="Google"]'
browser = Chrome()
browser.get(SETTINGS_PAGE_URL)
dropdown = browser.find_element_by_id(SEARCH_ENGINE_DROPDOWN_ID)
option = dropdown.find_element_by_xpath(SEARCH_ENGINE_CHOICE_XPATH)
option.click()

无论如何,如果没有页面的HTML代码,我只能为您提供有关XPath的一般建议。请参阅本页:http://zvon.org/xxl/XPathTutorial/Output/example1.html

它帮助我理解了XPath方法

最新更新