【问题标题】:How to click in the link in a herf in python如何在python中单击href中的链接
【发布时间】:2022-01-13 16:51:13
【问题描述】:

如何在herf中点击链接,链接是字符串

<a href="/pages/creation_flow/?step=profile_pic&amp;draft_id=597215097432581&amp;page_id=11020432423337" class="inv" id="u_0_1_sX" data-sigil="no_mpc">تخطي</a>

【问题讨论】:

    标签: python python-3.x python-2.7 selenium selenium-webdriver


    【解决方案1】:

    一般来说,可以通过点击元素本身来完成。
    如果此定位器是正确且唯一的,您可以执行以下操作:

    driver.find_element_by_xpath('//a[contains(@href,"/pages/creation_flow/?step=profile_pic")]').click()
    

    我无法确定定位器,因为您要共享指向页面或整个页面 HTML 的链接。
    此外,您可能需要在访问它之前添加一些延迟。

    【讨论】:

      【解决方案2】:

      要单击文本为 تخطي 的元素,您可以使用以下任一Locator Strategies

      • 使用link_text

        driver.find_element(By.LINK_TEXT, "تخطي")
        
      • 使用css_selector

        driver.find_element(By.CSS_SELECTOR, "a.inv[href^='/pages/creation_flow/?step=profile_pic']").click()
        
      • 使用xpath

        driver.find_element(By.XPATH, "//a[@class='inv' and starts-with(@href, '/pages/creation_flow/?step=profile_pic')][text()='تخطي']").click()
        

      【讨论】:

        猜你喜欢
        • 2021-12-03
        • 1970-01-01
        • 1970-01-01
        • 2010-11-27
        • 1970-01-01
        • 1970-01-01
        • 2016-11-06
        • 2015-08-18
        • 2016-12-28
        相关资源
        最近更新 更多