1

I am using selenium and chrome to automate the clicks of a page with python.

I am getting stuck not being able to click on the following href link:

<a href="javascript:void(0)" class="addSuppData-trigger pts" data-target="edit_3-1" style="padding-right:6px;float:right;">
            <i class="material-icons black-text tiny-small">edit</i></a>

I have tried using xpath, css, and linktext to no avail.

sample code:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="row-group-1"]/td[1]/div/div[2]/a/i' ))).click()

The goal is to click the pen, then select the item from the drop down. screen shot of button

The second highlight line is the pen. html tree

1 Answer 1

1

The element seems to be a dynamic element and to click on it you need to induce WebDriverWait for the desired element to be clickable and you can use either of the following solutions:

  • Using CSS_SELECTOR:

    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.addSuppData-trigger.pts[data-target^='edit_']>i.material-icons.black-text.tiny-small"))).click()
    
  • Using XPATH:

    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='addSuppData-trigger pts' and starts-with(@data-target, 'edit_')]/i[@class='material-icons black-text tiny-small' and contains(., 'edit')]"))).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
    
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, though with either of these I am getting a timeout exception.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.