website automation with selenium along with python


Hy there! I am automating aliexpress with selenium and python where users can buy products at voice command and can purchase any type of product. now the problem is a color and size selection, I have tried x-path but every element have a different x-path for the same color and size, I want a selector for at least four colors and four sizes, for clearance I have given the image, code, and link to the page too. if anyone has the solution plz mention it. thanx in advance

code :

#for selecting color 2 of an third item, but different for every element

elif '2' in query:                                 

link to the page is :

image (marked)for required details is :attached image for clearence


to select the type you can use the css selector and you can use this selector changing the index based on what you want select; I’m selecting the image but I think with only the div class sku-property-image should be enough:

First Model CSS Selector:

ul[class='sku-property-list']  li:nth-child(1) div[class='sku-property-image'] img

If you want select the second one just change 1 for 2:

ul[class='sku-property-list']  li:nth-child(2) div[class='sku-property-image'] img

For the Size the question is a bit more complex because size and country have the same selector so in this case you have to get the father element and hardcode the child of what you are looking for, as u can see in the below selector the div:nth-child(2) indicate the size section, instead li:nth-child(1) which size select, 1=S, 2=M, etc… example:

First SIZE S CSS Selector:

div[class='sku-wrap'] div:nth-child(2) ul[class='sku-property-list'] li:nth-child(1) div[class='sku-property-text'] span

Second SIZE M CSS Selector:

div[class='sku-wrap'] div:nth-child(2) ul[class='sku-property-list'] li:nth-child(2) div[class='sku-property-text'] span

Answered By – Carlo 1585

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published