Home > Software engineering >  I am getting Problem in python list how to solve
I am getting Problem in python list how to solve

Time:12-17

usernames = ["Trinity Ball","Arely Strong"  ]

username1 = usernames[1]

driver.get("https://www.youtube.com/channel_switcher?next=/account&feature=settings")

sleep(18)

switch = driver.find_element_by_xpath("//yt-formatted-string[contains(text(), 'username1')]")
switch.click()

please help I stuck here for 2 days. it is saying Message:

no such element: Unable to locate element: {"method":"xpath","selector":"//yt-formatted-string[contains(text(), 'username1')]"}

CodePudding user response:

If you see the below error

no such element: Unable to locate element: {"method":"xpath","selector":"//yt-formatted-string[contains(text(), 'username1')]"}

It is clear that the variable you are passing to the xpath it is treating as a string not argument.

Use python format() function to pass the variable.

switch = driver.find_element_by_xpath("//yt-formatted-string[contains(text(), '{}')]".format(username1))
switch.click()
  • Related