[英]How to click on all connect button in linkedin with python & selenium?
[英]How to click on the button within linkedin profile using Selenium and Python
一個非常快速的問題。 我想使用 selenium 單擊我的 LinkedIN 個人資料中的按鈕以擴展區域。 不幸的是,我總是出錯。 在下面我試圖點擊的按鈕:
<button class="pv-profile-section__see-more-inline pv-profile-section__text-truncate-toggle link link-without-hover-state" aria-expanded="false" type="button">Mehr anzeigen
<li-icon aria-hidden="true" type="chevron-down-icon" class="pv-profile-section__toggle-detail-icon" size="small"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" data-supported-dps="16x16" fill="currentColor" width="16" height="16" focusable="false">
<path d="M8 9l5.93-4L15 6.54l-6.15 4.2a1.5 1.5 0 01-1.69 0L1 6.54 2.07 5z"></path>
</svg></li-icon></button>
到目前為止,這就是我一直在嘗試的:
driver.find_element_by_class_name("pv-profile-section__actions-inline ember-view")
不幸的是,這沒有用。 你有什么想法?
所需的元素是動態元素,因此要單擊該元素,您必須為element_to_be_clickable()
引入WebDriverWait ,並且您可以使用以下任一定位器策略:
使用CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.pv-profile-section__see-more-inline.pv-profile-section__text-truncate-toggle.link.link-without-hover-state"))).click()
使用XPATH
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='pv-profile-section__see-more-inline pv-profile-section__text-truncate-toggle link link-without-hover-state' and contains(., 'Mehr anzeigen')]"))).click()
注意:您必須添加以下導入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
更規范地說,您可以使用:
使用CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.pv-profile-section__see-more-inline.pv-profile-section__text-truncate-toggle.link.link-without-hover-state li-icon.pv-profile-section__toggle-detail-icon"))).click()
使用XPATH
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='pv-profile-section__see-more-inline pv-profile-section__text-truncate-toggle link link-without-hover-state' and contains(., 'Mehr anzeigen')]//li-icon[@class='pv-profile-section__toggle-detail-icon']"))).click()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.