Umar Dastgir
Umar Dastgir

Reputation: 724

Clicking table element using Python Selenium

I am working with python and selenium to click on the Upload button on a facebook page. The HTML associated with this seems to have a within a table tag. The html is as in the following image. The button circles is the one I am trying to press.

Can anyone please tell me how should I press this button? I am using Python 3.7

enter image description here

Upvotes: 1

Views: 405

Answers (1)

Mobin Al Hassan
Mobin Al Hassan

Reputation: 1044

There is a multiple way to click on button you can try any of one

By using Xpath without wait: try: driver.find_element_by_xpath('your Xpath').click() print('Button clicked ok') except Exception as e: print('Error in clicking BTN : ' + str(e))

By using Xpath with wait:

try:
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
        (By.XPATH, 'your Xpath'))).click()
    print('Button clicked ok')
except Exception as e:
    print('Error in clicking BTN : ' + str(e))

By using Css selector:

try:
        driver.find_element_by_css_selector('a._3m1z').click()
        print('Button clicked ok')
    except Exception as e:
        print('Error in clicking BTN : ' + str(e))

By using css selector with wait:

try:
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
        (By.CSS_SELECTOR, 'a._3m1z'))).click()
    print('Button clicked ok')
except Exception as e:
    print('Error in clicking BTN : ' + str(e))

you can copy xpath by right click on element >>copy>>xpath

Upvotes: 1

Related Questions