0
  1. 问题:我正在尝试单击href此处:

在此处输入图像描述

  1. 失败尝试:我尝试使用这些无济于事

    driver.find_element_by_link_text('Join').click()
    driver.find_element_by_partial_link_text('href').click()
    
4

2 回答 2

1

您可以使用 xpath 代替链接文本。

driver.find_element_by_xpath('//a[contains(text(), "John"]').click()

space或者在前面 加上John

driver.find_element_by_link_text(' Join').click()
于 2020-09-18T02:37:49.940 回答
0

To click on the element with text as Join you can use either of the following Locator Strategies:

  • Using partial_link_text:

    driver.find_element_by_partial_link_text("Join").click()
    
  • Using xpath:

    driver.find_element_by_xpath("//a[contains(., 'Join')]").click()
    

Ideally, to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using PARTIAL_LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Join"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(., 'Join')]"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
于 2020-09-18T22:38:52.730 回答