0
#start
i=0
r=("('/html/body/div[4]/div/div/div[2]/ul/div/li[")
p=("]/div/div[2]/div[1]/div/div/span/a')")

for f in range(7):
   i = i+1
   browser.find_element_by_xpath("{}{}{}".format(r,i,p)).click()
#end

error i am getting =selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression ('/html/body/div[4]/div/div/div[2]/ul/div/li[1]/div/div[2]/div[1]/div/div/span/a') because of the following error: TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type. (Session info: chrome=91.0.4472.77)

1 Answer 1

0

instead of this :

r=("('/html/body/div[4]/div/div/div[2]/ul/div/li[")
p=("]/div/div[2]/div[1]/div/div/span/a')")

do this :

i = 0
for f in range(7):
 driver.find_element_by_xpath("/html/body/div[4]/div/div/div[2]/ul/div/li[{0}]/div/div[2]/div[1]/div/div/span/a".format(str(i))).click()
 i = i+1

I would still suggest to not use this absolute xpath instead use relative xpath

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.