Search code examples
pythonselenium-webdriverlinkedin-api

can anyone suggest me, which Syntax of FindElement command can be used? Xpath / Full Xpath is not working for me in the LinkedIn bot


Xpath / Full Xpath is not allowing me to access Easy Apply in the LinkedIn bot. enter image description here

try:
    easy_apply = self.driver.find_element(By.XPATH, '//*[@id="+Yx8O6UNSU67JGJE1z0tug=="]/div/ul[1]/li[2]/a')
    easy_apply.click()
    print("Easy Apply - successfully triggered")
    time.sleep(2)

except:
    print("Error Can't hold the Easy apply.")

Solution

  • search for the "easy apply" button via text

    import time
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    
    # Create a WebDriver instance (e.g., Chrome)
    driver = webdriver.Chrome()
    
    # Open a web page
    driver.get("https://example.com")
    
    try:
        # Find the button/anchor with case-insensitive text "Easy Apply"
        easy_apply = driver.find_element(By.XPATH, "//a[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'easy apply')]")
    
        # Click the button
        easy_apply.click()
        # Log Success
        print("Easy Apply - successfully triggered")
        time.sleep(2)
    
    except:
        # Log Error
        print("Error Can't hold the Easy apply.")
    
    # Close the WebDriver when done
    driver.quit()