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,094
  • 3
  • 29
  • 48
cva6
  • 155
  • 3
  • 13

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
  • 441,113
  • 110
  • 1,021
  • 1,148