try:
driver.find_element(By.CSS_SELECTOR, "div[class='Overflowreact__OverflowContainer-sc-7qr9y8-0 jPSCbX Price--amount']").text() < Snipeprice
except NoSuchElementException:
pass
else:
print("Snipe found!")
This is my current attempt to find the element and then test if the text value is less than the snipe price. This is the HTML of what I'm trying to checkHTML code.
So basically i want to refresh the website, check for if there is a element that exists below a certain price and then do a certain task or just wait a certain amount and try again.
If there is any more info you need, add a comment, I'm new to coding and Stackoverflow so I don't know everything you would need.
CodePudding user response:
In this case, you could make your CSS selector a little lighter and change it to div.Price--amount (note that the correct way to select by class attribute is using .{class-name}).
Next thing you probably want, if I understand your problem right, is to select multiple elements and not just the first one. You can achieve this by calling find_elements instead of find_element.
The last thing is the .text() method returns a str object and you need to compare it by its numerical (float) value. You want to convert it first.
for element in driver.find_elements(By.CSS_SELECTOR, "div.Price--amount"):
try:
if float(element.text()) < Snipeprice:
print("We've got a match")
except ValueError:
print(value, "is not a valid price")
