首页 > 解决方案 > 无法定位元素(按钮)

问题描述

网站来源是:

<div id='product-touch'>
   <div class='left">
     <div class='space-a'>
       <button class="button-buy">
          <span> Add to basket</span>
      </button>
     </div>
   </div>

</div>

我尝试使用以下代码行单击“添加到购物篮”按钮:

d.find_element_by_xpath("//div[@id='product-touch']/div/div/button").click()

但我得到:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate....

我需要对 XPATH 非常具体,因为在 div id="product-touch" 之前有另一个 div id 具有相同的按钮 class="button-buy"

有任何想法吗?

标签: python-3.xselenium-webdriver

解决方案


推荐阅读