我在這里需要你的幫助。
如下圖所示,您將在影像中看到公司搜索框(例如:埃森哲)。我們通過硒發送公司名稱。名稱正在發送,但是當我們點擊第一個建議的名稱時,它沒有被點擊。
我正在處理linkedin上的belw URL:
我試過下面認為。
company_button = WebDriverWait(driver,delay).until(EC.presence_of_element_located((By.XPATH,'//button[@aria-label="Company filter. Clicking this button displays all Company filter options."]')))
company_button.click()
time.sleep(2)
company_send = driver.find_element_by_xpath('//div[@]//input')
company_send.send_keys("Office Depot")
auto_complete = driver.find_elements_by_xpath(
"//li[@class='search-reusables__collection-values-item']")
auto_complete[0].click()
我需要你的幫助。預先感謝您的建議。
uj5u.com熱心網友回復:
這是上述問題的作業代碼。我花了一段時間才找到下拉串列。所以,為了找到它,我首先在輸入框中搜索關鍵字后在IDE中列印所有HTML,然后搜索選項關鍵字,例如“埃森哲”和“埃森哲印度”。通過這種方式,我找到了訪問下拉專案所需的元素。
import time
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.maximize_window()
action = ActionChains(driver)
wait = WebDriverWait(driver, 5)
# Opening page and logging in
driver.get('https://www.linkedin.com/login?fromSignIn=true&trk=guest_homepage-basic_nav-header-signin')
driver.find_element_by_id("username").send_keys('Your UserID')
driver.find_element_by_id("password").send_keys('Your Password')
driver.find_element_by_xpath('//button[text()="Sign in"]').click()
# Search and Enter
time.sleep(5)
SearchTextBox = wait.until(EC.visibility_of_element_located((By.XPATH, '//input[@placeholder="Search"]')))
action.move_to_element(SearchTextBox).click().send_keys('Machine Learning').perform()
SearchTextBox.send_keys(Keys.ENTER)
# Click on Jobs
wait.until(EC.element_to_be_clickable((By.XPATH, '//button[text()="Jobs"]'))).click()
# Clicking company filter
company_button = WebDriverWait(driver, 10).until(EC.presence_of_element_located(
(By.XPATH, '//button[@aria-label="Company filter. Clicking this button displays all Company filter options."]')))
company_button.click()
# Send Accenture keyword in the inputbox
# Please modify the xpath as per your understanding. Relative path
wait.until(EC.presence_of_element_located((By.XPATH, '//input[@placeholder="Add a company"]'))).send_keys('Accenture')
time.sleep(5)
# Collect all the options
All_selection = driver.find_elements_by_xpath(
"//span[contains(@class,'search-typeahead-v2__hit-text t-14 t-black')]")
# Printing all the options
for i in All_selection:
print(i.text)
# Click on the first Option.
All_selection[0].click()
如果您有任何疑問,請告訴我。謝謝。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/384022.html
標籤:Python 蟒蛇-3.x 硒 硒网络驱动程序 硒铬驱动器
