Dilli Dilli - 10 months ago 56
Python Question

Using %s in substring

inputData = raw_input('time:')
find_elem = wait.until(EC.presence_of_element_located((By.XPATH, "//*[contains(text(), '%s')]"% inputData)))

I do not know exactly why my code isn't working. I'm trying to pass my rawinput. If I get rid of %s and just put a string. It works. By not working I mean, the script is suppose to stop scrolling until certain time I do in raw_input but it doesn't but if I just pass in my string without %s it stops and works just as I wish to.

Answer Source

You should use tuple for string formatting:

"%s" % (inputData)

UPDATE This fixed the problem, but I do not know why? I am not sure why this worked and fixed the problem. As suggested in comments, (inputData) is not even a tuple. And string formatting does not need the second argument to be tuple. The second argument can be a string.