Home > Software engineering >  Clicking on Buy now Button in Aliexpress Python Selenium
Clicking on Buy now Button in Aliexpress Python Selenium

Time:02-08

I am trying to Click on Buy now Button in Aliexpress Python Selenium

for example

https://www.aliexpress.com/item/4000001810642.html


clikcononbuynows= driver.find_element_by_css_selector('#root > div > div.product-main > div > div.product-info > div.product-action > span.buy-now-wrap > button')
clikcononbuynows.click()

enter image description here

Also one more issue I want to click on the Search button and write something like "android cable" but it doesn't click the code I am using for that is

search = driver.find_element_by_css_selector('#search-key')
search.send_keys('android data cable')

enter image description here

Kindly Let me know What I am missing and help me

CodePudding user response:

To type in the search box and click on Search:

driver.find_element(By.ID, "search-key").send_keys("android data cable")
driver.find_element(By.XPATH, "//div[@class='header-search-btn']//button[@type='submit']").click()

To click on Buy Now option:

driver.find_element(By.XPATH, "//div[@class='product-action']//button[text()='Buy Now']").click()

Updated per user query: Search Button Clicked Snapshot

Full code for Search button: Note the time delays:

driver.get("https://www.aliexpress.com/item/4000001810642.html")
time.sleep(5)
driver.find_element(By.ID, "search-key").send_keys("android data cable")
time.sleep(2)
driver.find_element(By.XPATH, "//div[@class='header-search-btn']//button[@type='submit']").click()

Please use webdriverwait instead of time.sleep

  •  Tags:  
  • Related