但是,页面中的添加"按钮都没有名称或ID.所以我不能使用Selenium软件包中的driver.find_element_by_id()命令.有人可以帮助我吗?解决方案要单击特定产品的任何特定添加按钮,您可以编写如下方法:def click_me(string): driver.find_element_by_xpath("//h3/a[@class='co-product__anchor' and contains(@title, '%s')]//following::button[1]" % (string)).click()现在,您可以单击任何通过其标题的 Add 按钮,如下所示:click_me("Munch") # Munch Bunch Double Up Strawberry & Vanilla Yogurts# orclick_me("ASDA") # ASDA Greek Style Fat Free Yogurt# orclick_me("Petits") # Petits Filous Apricot, Strawberry & Raspberry YogurtI need to auto click on any of the "Add" buttons in a web page like as the following address:"https://groceries.asda.com/search/yoghurt"But, none of the "Add" buttons in the page has name or id.So I can not use driver.find_element_by_id() command from Selenium package.Can any one help me? 解决方案 To click on any particular Add button for a particular product you can write a method as follows:def click_me(string): driver.find_element_by_xpath("//h3/a[@class='co-product__anchor' and contains(@title, '%s')]//following::button[1]" % (string)).click()Now you can click on any of the Add button passing their title as follows:click_me("Munch") # Munch Bunch Double Up Strawberry & Vanilla Yogurts# orclick_me("ASDA") # ASDA Greek Style Fat Free Yogurt# orclick_me("Petits") # Petits Filous Apricot, Strawberry & Raspberry Yogurt 这篇关于自动点击网页中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!