StaleElementReferenceException when trying to click on the links in a loop

前端 未结 3 1260
慢半拍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:30

    There's an easier way to do this. You can use an XPath that will specify the category name you want to click. That way you don't have to loop, it will find the desired element in one search.

    //span[@name='topCategory'][.='Beauty']
    

    I'm assuming you will be reusing this code. In cases like this, I would create a function that takes a string parameter which would be the category name that you want to click. You feed that parameter into the XPath above and you can then click any category on the page.

    I tested this and it's working.

提交回复
热议问题