I'm using Selenium in python to test a data table (not really a html table, combined by multiple divs)
That's what my table looks like:
<div class="products">
<div class="product">
<span class="original-price">20$</span>
<span class="discounted-price">10$</span>
</div>
<div class="product">
<span class="price">20$</span>
</div>
...
</div>
There are multiple products, some has discounted price.
This is my script:
products = self.driver.find_elements_by_css_selector('.products > div')
for product in products:
found_price = True
try:
original_price = product.find_element_by_css_selector('.original-price').text
reduced_price = product.find_element_by_css_selector('.discounted-price').text
except NoSuchElementException:
try:
original_price = product.find_element_by_css_selector('.price').text
reduced_price = original_price
except NoSuchElementException:
found_price = False
if found_price: check_price(original_price, reduced_price)
But my script runs very slowly. It sends a lot of request "remote_connection" each time the "find_element_by_css_selector" called like this one:
2018-02-27 13:48:08 [selenium.webdriver.remote.remote_connection] DEBUG: POST http://127.0.0.1:62147/session/14902b71a0f812fa74f81524f0eb1386/elements {"using": "css selector", "sessionId": "14902b71a0f812fa74f81524f0eb1386", "value": ".products > div .original-price"}
2018-02-27 13:48:08 [selenium.webdriver.remote.remote_connection] DEBUG: Finished Request
Any ideas to improve its performance ?
Thanks !