I have a website that has anywhere from 3 to 4 images on it. If it tries to acquire the 4th image and it's not there the program blows up. I want to check if the fourth is there, and if it is I want to acquire it, if not I want to go on with the program. I want to do it without using try and except. I've tried .isDisplayed could not get it to work.
This is the driver statement that acquires the image. Image3 = driver.find_element_by_xpath('//*[@id="goods_thumb_content"]/ul/li[3]').get_attribute("data-bigimg");
I'm using Selenium and here is the code:
#This is the code when all four images are present. and when it's not the last <li> <l/> is not
present.
<ul>
<li class="thumb_item active logsss_event_cl" data-isself="1" data-
bigimg="https://gloimg.rglcdn.com/rosegal/pdm-product-pic/Clothing/2021/03/09/source-
img/20210309165545_60473811b6a7c.jpg" data-zoomimg="https://gloimg.rglcdn.com/rosegal/pdm-
product-pic/Clothing/2021/03/09/source-img/20210309165545_60473811b6a7c.jpg" data-logsss-const-
value="{'x': 'change_pic'}" style="height: 131.6px;"> <img
src="https://gloimg.rglcdn.com/rosegal/pdm-product-pic/Clothing/2021/03/09/grid-
img/1618874299184494137.jpg?im_scale=w75_1x" alt="Plus Size Paisley Print Empire Waist
Asymmetric Tank Top - "> </li>
<li class="thumb_item logsss_event_cl" data-isself="1" data-
bigimg="https://gloimg.rglcdn.com/rosegal/pdm-product-pic/Clothing/2021/03/09/source-
img/20210309165545_60473811c9ce8.jpg" data-zoomimg="https://gloimg.rglcdn.com/rosegal/pdm-
product-pic/Clothing/2021/03/09/source-img/20210309165545_60473811c9ce8.jpg" data-logsss-const-
value="{'x': 'change_pic'}" style="height: 131.6px;"> <img
src="https://gloimg.rglcdn.com/rosegal/pdm-product-pic/Clothing/2021/03/09thumb-
img/1615251725078779977.jpg?im_scale=w75_1x" alt="Plus Size Paisley Print Empire Waist
Asymmetric Tank Top - "> </li>
<li class="thumb_item logsss_event_cl" data-isself="1" data-
bigimg="https://gloimg.rglcdn.com/rosegal/pdm-product-pic/Clothing/2021/03/09/source-
img/20210309165545_60473811df353.jpg" data-zoomimg="https://gloimg.rglcdn.com/rosegal/pdm-
product-pic/Clothing/2021/03/09/source-img/20210309165545_60473811df353.jpg" data-logsss-const-
value="{'x': 'change_pic'}" style="height: 131.6px;"> <img
src="https://gloimg.rglcdn.com/rosegal/pdm-product-pic/Clothing/2021/03/09thumb-
img/1615251725121900529.jpg?im_scale=w75_1x" alt="Plus Size Paisley Print Empire Waist
Asymmetric Tank Top - "> </li>
#The <li> below is not present when the fourth image is not there.
<li class="thumb_item logsss_event_cl" data-isself="1" data-
bigimg="https://gloimg.rglcdn.com/rosegal/pdm-product-pic/Clothing/2021/03/09/source-
img/20210309165545_60473811f1542.jpg" data-zoomimg="https://gloimg.rglcdn.com/rosegal/pdm-
product-pic/Clothing/2021/03/09/source-img/20210309165545_60473811f1542.jpg" data-logsss-const-
value="{'x': 'change_pic'}" style="height: 131.6px;"> <img
src="https://gloimg.rglcdn.com/rosegal/pdm-product-pic/Clothing/2021/03/09thumb-
img/1615251725802705831.jpg?im_scale=w75_1x" alt="Plus Size Paisley Print Empire Waist Asymmetric
Tank Top - "> </li>
</ul>