我是Selenium Python的新手。我正在嘗試運行以下代碼段。它適用於find_element_by_name,但不適用於find_element_by_xpath。如何在selenium python中使用xpath?
任何想法我做錯了什麼?
感謝
from selenium import webdriver
# create a new Firefox session
driver = webdriver.Firefox()
driver.implicitly_wait(10)
driver.maximize_window()
# navigate to the application home page
driver.get("https://www.google.co.uk/")
# get the search textbox
#search_field = driver.find_element_by_xpath("//@name='q'/") <<<<< NOT Working
search_field = driver.find_element_by_name("q")
search_field.clear()
# enter search keyword and submit
search_field.send_keys("phones")
search_field.submit()
如果下面的解決方案是正確的和爲你工作,然後請標記爲正確。 –