Selenium find element with variable value

Viewed 58

i want to click an element with a value, which will be inserted by user. I tried this:

def transition(action, value=none):
    if (action=='next_page'):
        button = driver.find_element_by_link_text('"value"')
        button.click()

  transition('next_page', value='car1')

The problem is that 'car1' value isn't inserted. What can i fix it?

1 Answers

What your code does, is actually calling the find_element function with the string "value", as you wrote it in quotation marks, making it a string literal

button = driver.find_element_by_link_text('"value"')

What you want to do is insert the name of the variable value without any "double" or 'single' quotation marks, like so.

button = driver.find_element_by_link_text(value)

As you are having a hard time dealing with such simple python syntax, I recommend you first learn the bare basics of the language before trying to write applications with it. There are a lot of free resources out there. I can recommend W3Schools as a website with text and interactive examples or if you are more of the video type of learner, I can recommend the course by freeCodeCamp.org or a video series by Tech With Tim. Though the last one didn't age really well.

Related