0
driver.find_element_by_xpath("/html/body/div[3]/div[3]/div[2]/div/div[2]/div[1]/div/div[3]").text

instead of this, I want something like

driver.find_element_by_xpath("/html/body/div[3]/div[3]/div[",i,"]/div/div[2]/div[1]/div/div[3]").text

this to increase i in a loop. But when I use this one the error message I have is this

"InvalidSelectorException: Message: Invalid locator values passed in"

1 Answer 1

1

You are using the wrong syntax for string concatenation. Try substituting in the value of i instead:

driver.find_element_by_xpath("/html/body/div[3]/div[3]/div[%d]/div/div[2]/div[1]/div/div[3]" % i).text
Sign up to request clarification or add additional context in comments.

1 Comment

@zahedae it works when printing because print() accepts multiple arguments, and concatenates them behind the scenes. For everything else, you need to use one of string1 + string2, "foo" + "bar", " ".join(string1, string2), "foo %s bar" % "baz", the str.format() method, and probably some others I've missed. Google python string concatenation and string formatting for more info

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.