亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如果使用 XPath python selenium 匹配父類和 URL,我無法找到兩個子類

如果使用 XPath python selenium 匹配父類和 URL,我無法找到兩個子類

慕勒3428872 2023-03-16 09:53:28
您好,我一直在嘗試為一位家長找到符合以下要求的元素:這是下面的鏈接 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 選擇器。


查看完整回答
反對 回復 2023-03-16
  • 1 回答
  • 0 關注
  • 108 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號