Home > Mobile >  Making a function that uses driver from selenium(in python)
Making a function that uses driver from selenium(in python)

Time:06-29

def button_click(xpath):
    button = driver.find_element(by=By.XPATH, value=xpath)
    button.click()

Function takes xpath as attribute and then clicks the respective button the xpath directs to.

How do i go about it? (always gives this error : catching classes that do not inherit from BaseException is not allowed )

CodePudding user response:

No reason that your code shouldn't work, there is obviously some other problem somewhere else in your code. In this function, it's better to pass in driver variable as an argument than to use a global, or you will run into problems when unit-testing. Also remember to catch the Exception when xpath is not found in the page.

  • Related