2
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.

5
  • 2
    It sounds like you have one string that works (the one you hard-coded) and one that doesn't (the one you've made with %s). Print them out and spot the difference. Commented Nov 6, 2016 at 1:28
  • what means isn't working - do you get error message or what ? Commented Nov 6, 2016 at 1:30
  • @furas In this case it needs to stop scrolling but continues to scroll. but if I get rid of %s it stops at the desired amount I want. Commented Nov 6, 2016 at 1:30
  • As @smarx said - compare both strings Commented Nov 6, 2016 at 1:31
  • Yes. I compared the both string by doing this string = "//*[contains(text(), '%s')]" % inputDate print string //*[contains(text(), '8 mins')] Just how I wanted it to. but when I use that in my actual function it doesn't work. Commented Nov 6, 2016 at 1:34

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I have no explanation for why this would fix something... (inputData) is not a tuple. (inputData,) would be. Regardless, you can certainly just use a string in this sort of construction "%s" % "hello world" works just fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.