StaleElementReferenceException when trying to click on the links in a loop

前端 未结 3 1261
慢半拍i
慢半拍i 2021-01-26 10:54

Please click on the link below to see the link \"BEAUTY\" on which I am clicking 1. I am using this code to click on the \"Beauty\" link

driver = webdriver.Ch         


        
3条回答
  •  深忆病人
    2021-01-26 11:39

    Try this:

    from selenium import webdriver
    
    print("bot started")
    
    #chromeOptions = webdriver.ChromeOptions()
    
    #driver = webdriver.Chrome(chrome_options=chromeOptions)
    
    def specific_text(text, ea):
        return str(text) == ea.text
    
    driver = webdriver.Chrome("C:\\Users\\gaurav\\Desktop\\chromedriver_win32\\chromedriver.exe")
    driver.maximize_window()
    driver.get("http://shop.davidjones.com.au")
    object_ = driver.find_elements_by_name('topCategory')
    text_headers = [str(specific_text('Beauty', ea)) for ea in object_]
    #print(text_headers)
    index_text = text_headers.index("True")
    #print(index_text)
    object_[index_text].click()
    

提交回复
热议问题