How can I verify the presence of a certain HTML tag within another HTML tag using Selenium Webdriver (Python)?

Question!

Basically, I want to know if a tag is within a tag. The data is dynamically generated, which is why I am using selenium webdriver. The HTML looks like:

<td class="something">
    <span></span>
</td>

The issue is, however, there are times when there is no <span> tag within a <td> tag. I want to find out when this occurs and when this does not occur. I am scraping the website using scrapy (and finding elements using xpath) so the data will go into a dictionary on a json file. So, when the scraping is done, the resulting data in the json file will look like:

{"data": ["*", " ", "*", " ", " ", " "]}

Where the * corresponds to instances where the <span> tag is present within the <td> tag and the blank spaces correspond to instances where the <span> tag is not present. Let me know if further clarification is needed and thanks for any help.



Answers

The example by paul should get you close, however, why are you selecting repeatedly? It would make more sense to me to wait for the condition you want to happen and set a timeout to verify consistent performance levels.

    WebDriverWait wait = new WebDriverWait([Instance of IWebDriver goes here], TimeSpan.FromSeconds(5));
    wait.Until (d=
By : mutt


This video can help you solving your question :)
By: admin