Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
Python 3.x 如何使用Selenium Python单击元素?_Python 3.x_Selenium_Selenium Webdriver_Xpath_Webdriverwait - Fatal编程技术网

Python 3.x 如何使用Selenium Python单击元素?

Python 3.x 如何使用Selenium Python单击元素?,python-3.x,selenium,selenium-webdriver,xpath,webdriverwait,Python 3.x,Selenium,Selenium Webdriver,Xpath,Webdriverwait,我正试图尽可能多地概括一个代码,以便抓取易趣网站。 我现在陷入了这样的境地: 以下是我开始的URL: https://www.ebay.co.uk/sch/i.html?_from=R40&_nkw=iphone+12&_oac=1 我想点击“更多过滤器”按钮,然后特别选择“品牌”选项,获得可用品牌的列表 这就是我到目前为止能够做到的: url = 'https://www.ebay.co.uk/sch/i.html?_from=R40&_nkw=iphone+12&a

我正试图尽可能多地概括一个代码,以便抓取易趣网站。 我现在陷入了这样的境地:

以下是我开始的URL:

https://www.ebay.co.uk/sch/i.html?_from=R40&_nkw=iphone+12&_oac=1
我想点击“更多过滤器”按钮,然后特别选择“品牌”选项,获得可用品牌的列表

这就是我到目前为止能够做到的:

url = 'https://www.ebay.co.uk/sch/i.html?_from=R40&_nkw=iphone+12&_oac=1'
driver = webdriver.Chrome()
driver.get(url)
driver.find_element_by_id('s0-14-11-0-1-2-6-2').click()
单击()后,子面板打开,我得到需要更改的内容:

<div role="tab" class="x-overlay-aspect " data-aspecttitle="aspect-Brand" aria-selected="false" aria-controls="refineOverlay-subPanel" id="c3-mainPanel-Brand"><span class="x-overlay-aspect__label">Brand</span><svg focusable="false" aria-hidden="true" class="x-overlay-aspect__check-icon svg-icon icon-check" role="img" aria-label="Filter applied"><use xlink:href="#svg-icon-check"></use></svg></div>
品牌
如果我在“品牌”上手动选择(即用光标单击),我会得到以下结果:

<div role="tab" class="x-overlay-aspect active" tabindex="0" data-aspecttitle="aspect-Brand" aria-selected="true" aria-controls="refineOverlay-subPanel" id="c3-mainPanel-Brand"><span class="x-overlay-aspect__label">Brand</span><svg focusable="false" aria-hidden="true" class="x-overlay-aspect__check-icon svg-icon icon-check" role="img" aria-label="Filter applied"><use xlink:href="#svg-icon-check"></use></svg></div>
品牌
不幸的是,我几乎不懂Javascript,所以,尽管还有其他类似的帖子,但我不知道如何从这里继续下去,以最终获得我需要的信息


我希望你能帮忙,我提前谢谢你

要单击更多过滤器,然后单击品牌,您需要引导
元素成为可点击的()
,您可以使用以下任一选项:

  • 代码块:

    driver.get("https://www.ebay.co.uk/sch/i.html?_from=R40&_nkw=iphone+12&_oac=1")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(., 'More filters')]"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Brand']"))).click()
    
  • 注意:您必须添加以下导入:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • 浏览器快照: