Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过Selenium和Python单击元素_Python_Python 3.x_Selenium Webdriver_Xpath_Css Selectors - Fatal编程技术网

如何通过Selenium和Python单击元素

如何通过Selenium和Python单击元素,python,python-3.x,selenium-webdriver,xpath,css-selectors,Python,Python 3.x,Selenium Webdriver,Xpath,Css Selectors,我正在尝试单击产品页面中的某个项目以向我的购物车添加某些内容,但我无法这样做,因为我遇到了许多错误或什么也没有发生。 这是我的代码: i = driver.find_element_by_xpath("//button[@class='exclusive']") i.click 这是网页代码: 添加到购物车 要在产品页面中单击要添加到购物车的项目,您可以使用以下任一选项: 使用css\u选择器: driver.find_element_by_css_selector("p.buttons

我正在尝试单击产品页面中的某个项目以向我的购物车添加某些内容,但我无法这样做,因为我遇到了许多错误或什么也没有发生。 这是我的代码:

i = driver.find_element_by_xpath("//button[@class='exclusive']")
i.click
这是网页代码:

添加到购物车


要在产品页面中单击要添加到购物车的项目,您可以使用以下任一选项:

  • 使用
    css\u选择器

    driver.find_element_by_css_selector("p.buttons_bottom_block.no-print>button.exclusive[name='Submit']>span").click()
    
  • 使用
    xpath

    driver.find_element_by_xpath("//p[@class='buttons_bottom_block no-print']/button[@class='exclusive']/span[text()='Add to cart']").click()
    
i.单击()
。纠正这一点也许你的语法是错误的我得到了很多错误是什么?发帖将它们添加到问题中。