0

I saw that part of my question was answered before: AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath'

And I believe that now if I want to accomplish (for example):

driver.find_element_by_xpath('//*[@id="#ICClear"]').click()

I need to use:

driver.find_element("xpath", '//*[@id="#ICClear"]').click()

However, I'm very unsophisticated in programming, so in my code I, for better or worse, have one of my scripts "defining" this functionality as:

xpath = driver.find_element_by_xpath

So that later on I would use:

xpath("""//*[@id="#ICClear"]""").click()

(Note that I do more than just use the click method, I also send text, etc.)

I have about 20 or so scripts that import this definition of "xpath" and use it throughout. I'm not sure how to change my 'xpath' definition to work with the new format so that I can still reference it without refactoring all of the code that relies on this.

RoccoMaxamas
  • 339
  • 2
  • 5
  • 14

1 Answers1

1

I haven't tested this, but I would expect this to do what you are asking for:

def xpath(xpath_expr):
    return driver.find_element("xpath", xpath_expr)

This would replace your definition of xpath as driver.find_element_by_xpath in your common script.

Luke Woodward
  • 63,336
  • 16
  • 89
  • 104