<div class="gift"> <button type="button" data-log-actionid-label="gift" data-log-body="{"current_product_no" : "1003072802", "group_product_no" : "", "group_product_firstview_no" : "", "product_price" : "5600", "send_impression": "Y"}" data-is-send-log="true"> togift <span class="ic_new">new</span> </button></div>無法通過文本使用,因為此頁面有很多文本togift我怎樣才能點擊這個按鈕?
3 回答

慕斯王
TA貢獻1864條經(jīng)驗 獲得超2個贊
沒有足夠的 html 源代碼讓我們知道如何編寫正確且簡短的元素位置聲明。所以只需嘗試以下操作xpath expressions:
"//div[@class='gift']/button[contains(text(),'togift') and ./span[contains(text(),'new')]]"
"//div[@class='gift']/button[contains(text(),'togift')]"
"//div[@class='gift']/button"

月關寶盒
TA貢獻1772條經(jīng)驗 獲得超5個贊
您可以嘗試使用class name:
div = driver.find_element_by_class_name('gift')
btn = div.find_element_by_xpath('.//button')
btn.click()
如果有其他標簽具有相同的類名,那么您可以使用css selector或full xpath

拉莫斯之舞
TA貢獻1820條經(jīng)驗 獲得超10個贊
應該點擊 div 類禮物按鈕。
driver.find_element_by_xpath("div[class='gift']/button").click()
添加回答
舉報
0/150
提交
取消