您好,我一直在嘗試為一位家長找到符合以下要求的元素:這是下面的鏈接 https://shopee.com.my/search?keyword=mattressParent Class<div class ="col-xs-2-4 shopee-search-item-result__item" data-sqe="item">Child class<a data-sqe="link" href= "all urls that is printed in python.">Child class contains this element<div class = "_1gkBDw _2O43P5"><div class = "_1HvBLA"><div class = "_3ao649" data-sqe="ad"> Ad</div>只需檢查頂部欄的元素:其中顯示了突出顯示的“廣告”這是我要實現的目標:用戶點擊包含產品頁面廣告欄的特定產品頁面。這是我的代碼: WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='col-xs-2-4 shopee-search-item-result__item' and @data-sqe='item'][.//a[@data-sqe='link' and @href='" + result[i] +"']]"))).click()Xpath 假設找到父級//div[@class="col-xs-2-4 shopee-search-item-result__item"]和一個href "/Direct-Export-Super-Single-Mattress-Synthetic-Latex-(6-Inches)-i.281593956.6140904430"完美運行的父級并單擊它。WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='col-xs-2-4 shopee-search-item-result__item' and @data-sqe='item'][@class='_1HvBLA'][@class = '_3ao649' and @data-sqe = 'ad'][.//a[@data-sqe='link' and @href='" + all_urls[i] +"']]")))//div[@class="_1HvBLA"]當我嘗試找到另外 2 個元素時,父子元素一起單擊它時我不起作用,//div[@class="_3ao649"]因為它似乎沒有單擊它。
1 回答

HUWWW
TA貢獻1874條經驗 獲得超12個贊
您不必使用類。您可以使用 CSS 選擇器,例如
div[data-sqe=item] a[data-sqe=link]
這應該有效(在開發人員工具中的 Chrome 瀏覽器元素搜索中嘗試。
我建議你通過“CSS diner”在線游戲來學習使用 CSS 選擇器。
添加回答
舉報
0/150
提交
取消