I am attempting to search a page for an element which prints a price (for that listing) and then increments the integer as to not print the same price again, but the price for the next listing. Here is the code I am using. It is already inside a for loop which I have not written out as it is extensive.
price_int = 1
price = driver.find_element(By.XPATH, "//span[@class='market_table_value'][price_int]")
print(price.text)
price_int+=1
#(Loop repeats)
When I replace price_int with a value such as 1 or 2 the correct respective price is returned. I am confused as to why the code is not working. It returns this error when built.
"selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: The result of the xpath expression "/" is: [object HTMLDocument]. It should be an element."
Any help is appreciated, I get the feeling this is a simple fix but I have not been able to find it.