Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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
无法选择LinkedIn';地点';使用Python Selenium的按钮_Python_Selenium_Xpath_Automation - Fatal编程技术网

无法选择LinkedIn';地点';使用Python Selenium的按钮

无法选择LinkedIn';地点';使用Python Selenium的按钮,python,selenium,xpath,automation,Python,Selenium,Xpath,Automation,我正试图点击LinkedIn中的位置下拉列表。通过在LinkedIn搜索栏中搜索某些内容,然后单击“人员”,您将进入LinkedIn页面的这一部分 这是HTML元素: <button aria-checked="false" role="button" aria-label="Locations filter. Clicking this button displays all Locations filter options."

我正试图点击LinkedIn中的位置下拉列表。通过在LinkedIn搜索栏中搜索某些内容,然后单击“人员”,您将进入LinkedIn页面的这一部分

这是HTML元素:

<button aria-checked="false" role="button" aria-label="Locations filter. Clicking this button displays all Locations filter options." 
id="ember745" class="artdeco-pill artdeco-pill--slate artdeco-pill--2 artdeco-pill--choice ember-view search-reusables__filter-pill-button" aria-controls="artdeco-hoverable-artdeco-gen-54" aria-expanded="false" data-control-name="filter_top_bar_select" type="button">  
      Locations
<!---->      <li-icon aria-hidden="true" type="caret-filled-down-icon" class="search-reusables__pill-button-caret-icon" size="small"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" data-supported-dps="16x16" fill="currentColor" class="mercado-match" width="16" height="16" focusable="false">
  <path d="M8 11L3 6h10z" fill-rule="evenodd"></path>
</svg></li-icon>
    
</button>
我在这方面花了很多时间,但还没有找到解决方案

点击位置后,我还想选择美国,然后点击公司名称并写下公司名称


下一部分: 这是“美国”位置的html。我想点击“美国”并搜索该过滤器

<li class="search-reusables__collection-values-item">
        <input aria-label="Filter by United States" name="United States" id="geoUrn-103644278" class="search-reusables__select-input" data-control-name="filter_detail_select" type="checkbox" value="103644278">
        <label for="geoUrn-103644278" class="search-reusables__value-label">
          <p class="display-flex">
            <span class="t-14 t-black--light t-normal">
              United States
            </span>
          </p>
        </label>
<!---->      </li>

可以使用此XPath找到该特定按钮:

//span//button[contains(@aria-label,'Locations filter')]
因此,可以通过

locations_btn = WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.XPATH, '//span//button[contains(@aria-label,"Locations filter")]')))
“美国”位置可由以下人员选择:

WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.XPATH, '//div[contains(@id,"locations-filter")]//li[@class="search-reusables__collection-values-item"]//span[contains(.,"United States")]'))).click()
或者,如果要单击该复选框,可以使用以下内容:

WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.XPATH, '//div[contains(@id,"locations-filter")]//li[@class="search-reusables__collection-values-item" and .//span[contains(.,"United States")]]//input'))).click()

谢谢@Prophet。你能写出代码的全部语句吗?你是什么意思?我的意思是为上面的语句编写完整的代码,比如:browser.find_element_by_xpath…etcis这就是你想要的?更新的答案谢谢!你能再帮我一件事吗。我想选择美国作为一个地点。我应该如何选择它?我将粘贴问题中的html。
WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.XPATH, '//div[contains(@id,"locations-filter")]//li[@class="search-reusables__collection-values-item"]//span[contains(.,"United States")]'))).click()
WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.XPATH, '//div[contains(@id,"locations-filter")]//li[@class="search-reusables__collection-values-item" and .//span[contains(.,"United States")]]//input'))).click()