[英]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.