toggleSwitch Selenium Button for searchtempest.com
Try the below code, which will untoggle all the options except eBay results.
from selenium import webdriverfrom time import sleepdriver = webdriver.Chrome("chromedriver.exe");driver.get("https://www.searchtempest.com/search?search_string=desk&category=8&subcat=sss&hasPic=&maxAsk=&maxYear=&minAsk=&minYear=&srchType=&cityselect=zip&location=90210&maxDist=500®ion_us=1®ion_can=1®ion_mex=1&Region=combined&addCities=&subCities=&q=desk++%22for+sale%22");element = driver.find_element_by_id('hybridSearchPreferencesToggle')element.click()element = driver.find_element_by_xpath("//input[@id='showcl_hybrid']/parent::div")sleep(3)element.click()element = driver.find_element_by_xpath("//input[@id='showat_hybrid']/parent::div")element.click()element = driver.find_element_by_xpath("//input[@id='showaz_hybrid']/parent::div")element.click()element = driver.find_element_by_xpath("//input[@id='showzr_hybrid']/parent::div")element.click()print("Done...")
I have used sleep() method for giving 3 seconds delay before doing the un-toggling, you can replace this with WebDriverWait if you want to.
clicked=Falsecount=30while not clicked or count > 0: try: element = driver.find_element_by_xpath("//span[@class='PUsnl' and text()='Done']/parent::button") element.click() print("Clicked...") break except: print("Not Clicked...") sleep(1) count-=1
Use the above code for clicking on the 'Done' button. As some pop up is coming on the right side 'Welcome to tutorial mode', the above code will wait until that pop up gets disappeared then will click on the 'Done' button
You can try to close that pop up instead of waiting for that pop up to gets disappeared or you can use WebDriverWait for 'Done' locator until it becomes clickable. I hope it helps...