0

Unable to click the linktext using selenium execute_script function

This is what I am tring to do:

self.driver.execute_script("document.getElementByLinktext('Level 1s').click;")
Giordano
  • 5,422
  • 3
  • 33
  • 49
cva6
  • 325
  • 7
  • 15

1 Answers1

2

You are not calling the click() method:

self.driver.execute_script("document.getElementByLinktext('Level 1s').click();")
                                                                   FIX HERE^

Note that you can also locate the element with selenium and then pass it into the script:

link = self.driver.find_element_by_link_text('Level 1s')
self.driver.execute_script("arguments[0].click();", link)

You can also perform the click via selenium directly if applicable:

link.click()

Also related:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195