0
如果有人知道如何完成編寫XPATH以從下拉菜單中引出高位鏈接選項。我正在嘗試打印選定的選項。到目前爲止,我到:使用Python中的Selenium從父類創建XPATH
print(driver.find_element_by_xpath(".//[@id='productGrid']/div[1]/div[1]/div/select").text)
這將打印像所有avaialable選項,以便:
精選
Name (A-Z)
Name (Z-A)
Price (Low-High)
Price (High-Low)
我只需要選擇「名稱AZ」來進行打印,但不知道如何用XPATH定位元素的這個特定選項。看起來我需要用XPATH編寫一些東西來獲取子類的子類。父類是:id ='productGrid'。 'select'是一個子類。 '選項值'=名稱(A-Z)是我無法得到的下一步。
火路徑腳本是這樣的:
<select onchange="setLocation(this.value)"> **(I am here**)
<option value="http://www.titleboxing.com/gloves/training-sparring-boxing- gloves?dir=desc&order=position"> Featured </option>
<option value="http://www.titleboxing.com/gloves/training-sparring-boxing-gloves?dir=asc&order=name" selected="selected"> Name (A-Z) </option> (*I need to get here*)
<option value="http://www.titleboxing.com/gloves/training-sparring-boxing-gloves?dir=desc&order=name"> Name (Z-A) </option>
<option value="http://www.titleboxing.com/gloves/training-sparring-boxing-gloves?dir=asc&order=price"> Price (Low-High) </option>
<option value="http://www.titleboxing.com/gloves/training-sparring-boxing-gloves?dir=desc&order=price"> Price (High-Low) </option>