I currently have a Selenium script that is running through a list of part numbers on a website and capturing some information such as product name (pulled from the page title).
I have noticed that some of the product is identified as "DISCONTINUED" (through a span) and so I would like to be able to capture that information so that I can ignore all of those products.
On the website in general, they denote these products through:
<span data*="">DISCONTINUED</span>
Any other products that are valid will not have this information on it, and so in this case I want to ensure that the script doesn't crash and just captures a blank value.
I tried using:
driver.find_element(By.XPATH, '//html/body/div/div/section/div/section/div/div/section/div/div/div/div/div/span/span[text()="DISCONTINUED"]')
However I get this error:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//html/body/div/div/section/div/section/div/div/section/div/div/div/div/div/span/span[text()="DISCONTINUED"]"}
I did make sure to use only a single part number that did indeed have a DISCONTINUED on it.
I also did load up the page in dev tools and searched for that specific xpath and it did indeed highlight the proper section:
Searched:
//html/body/div/div/section/div/section/div/div/section/div/div/div/div/div/span/span
Highlighted:
<span data*="">DISCONTINUED</span>
What is the best way to do this? Also, I need to check to see how to include a blank value by default so that it will not crash when a current product is retrieved.