您好,我一直在嘗試為一位家長(zhǎng)找到符合以下要求的元素:這是下面的鏈接 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>只需檢查頂部欄的元素:其中顯示了突出顯示的“廣告”這是我要實(shí)現(xiàn)的目標(biāo):用戶(hù)點(diǎn)擊包含產(chǎn)品頁(yè)面廣告欄的特定產(chǎn)品頁(yè)面。這是我的代碼: 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 假設(shè)找到父級(jí)//div[@class="col-xs-2-4 shopee-search-item-result__item"]和一個(gè)href "/Direct-Export-Super-Single-Mattress-Synthetic-Latex-(6-Inches)-i.281593956.6140904430"完美運(yùn)行的父級(jí)并單擊它。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"]當(dāng)我嘗試找到另外 2 個(gè)元素時(shí),父子元素一起單擊它時(shí)我不起作用,//div[@class="_3ao649"]因?yàn)樗坪鯖](méi)有單擊它。
1 回答

HUWWW
TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊
您不必使用類(lèi)。您可以使用 CSS 選擇器,例如
div[data-sqe=item] a[data-sqe=link]
這應(yīng)該有效(在開(kāi)發(fā)人員工具中的 Chrome 瀏覽器元素搜索中嘗試。
我建議你通過(guò)“CSS diner”在線(xiàn)游戲來(lái)學(xué)習(xí)使用 CSS 選擇器。
添加回答
舉報(bào)
0/150
提交
取消