Home > front end >  i am trying to select hidden dropdown menu option using selenium webdriver python but it throw "
i am trying to select hidden dropdown menu option using selenium webdriver python but it throw "

Time:03-23

i trying this code

import requests as req
from selenium.webdriver.common.by import By
from selenium import webdriver
#from selenium.webdriver.support.ui import WebDriverWait
#from selenium.webdriver.support import expected_conditions as EC
#from selenium.webdriver.support.select import Select as select
driver = webdriver.Chrome(f'F:\Deep Learning\chromedriver')
driver.maximize_window()
driver.get('https://www.naukri.com/')
driver.implicitly_wait(10)
driver.find_element(By.XPATH,'//input[@placeholder="Enter skills / designations / companies"]').send_keys('data scientist')
driver.find_element(By.XPATH,'//input[@placeholder="Enter location"]').send_keys('pune,Delhi NCR,Hydrabad')
driver.find_element(By.CSS_SELECTOR,".dropdownMainContainer").click
driver.implicitly_wait(10)

#driver.find_element(By.XPATH,'//*[@id="expereinceDD"]').click
driver.implicitly_wait(10)
driver.find_element(By.XPATH,"//span[normalize-space()='2 years']").click
driver.quit()

but it throw error massege

before click on the "select experiance" it show! select experiance screenshot before clicking on"select experiance" after click on the "select experiance" dropdown menu its show after click on it

error massage is "Message: no such element: Unable to locate element" for reference i given the link https://www.naukri.com/ error massege

how can i click that "select experiance" menu so to select one of the option

CodePudding user response:

Your main problem here is that you trying to use non-existing .click method instead of Selenium .click() method.
Also, no need to define driver.implicitly_wait(10) several times. This command sets the implicitly wait for the driver for the entire session.
This code works:

import requests as req
from selenium.webdriver.common.by import By
from selenium import webdriver
#from selenium.webdriver.support.ui import WebDriverWait
#from selenium.webdriver.support import expected_conditions as EC
#from selenium.webdriver.support.select import Select as select
driver = webdriver.Chrome(f'F:\Deep Learning\chromedriver')
driver.maximize_window()
driver.get('https://www.naukri.com/')
driver.implicitly_wait(10)
driver.find_element(By.XPATH,'//input[@placeholder="Enter skills / designations / companies"]').send_keys('data scientist')
driver.find_element(By.XPATH,'//input[@placeholder="Enter location"]').send_keys('pune,Delhi NCR,Hydrabad')
driver.find_element(By.CSS_SELECTOR,".dropdownMainContainer").click()
driver.find_element(By.XPATH,"//span[normalize-space()='2 years']").click()
driver.quit()

CodePudding user response:

Your code works fine, if you use click() instead of click.

driver.find_element(By.CSS_SELECTOR,".dropdownMainContainer").click()


driver.find_element(By.XPATH,"//span[normalize-space()='2 years']").click()

Also, use explicit wait instead of implicit wait. By Explicit wait, I mean WebdriverWait. It helps with good practice.

  • Related