Instgram(https://www.instagram.com/) 現在登入後在右邊有個搜尋的Icon,
圖:https://imgur.com/a/RIyY1Rm
這個Icon 和 點擊以後出現的搜尋欄位我用XPATH都沒辦法定位成功, 請各位協助
謝謝
#搜尋按鈕XPATH:
XPATH:'//*[@id="mount_0_0_Rh"]/div/div/div/div[1]/div/div/div/div[1]/div[1]/d
iv[1]/div/div/div[1]/div/div[2]/div[2]/div/a/div/div/div/div/svg'
Code:
#搜尋按鈕XPATH定位
search_path =
'//*[@id="mount_0_0_Rh"]/div/div/div/div[1]/div/div/div/div[1]/div[1]/div[1]/div/div/div[1]/div/div[2]/div[2]/div/a/div/div/div/div/svg'
search = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, search_path))
)
search.click()
#按鈕點擊後搜尋欄位XPATH定位
searchbox_xpath = '//*[contains(concat( " ", @class, " " ), concat( " ",
"x1n2onr6", " " ))]'
searchbox = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, searchbox_xpath))
)
keyword = '#Car'
searchbox.send_keys(keyword)
time.sleep(1)
searchbox.send_keys(Keys.RETURN)