Mode 38: Exercise for dice.com | Selenium Python Forum
G
Gaurav Valera Posted on 10/02/2021

Hi,

In http://www.dice.com/, selenium does not perform click acontion on desired (or any option) populated after entering keyword under 'Job Title'.

PFA screenshot

Code:

from selenium import webdriver
import time

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome(executable_path='C:/Git_Data/automationFrameworks/chromedriver.exe')
driver.maximize_window()
driver.implicitly_wait(10)
driver.get("http://www.dice.com/")
wait = WebDriverWait(driver, 10)
driver.find_element_by_css_selector('div#searchInput-div > form > div > div.flex-grow-1.mr-md-2 > div > dhi-new-typeahead-input > div > input').send_keys('Selenium')
time.sleep(5)
options = driver.find_elements_by_xpath("//*[@id='cdk-overlay-0']/div/dhi-typeahead-grouped-list/div")
print(len(options))


for i in options:
    print(i.text)

    if i.text == 'selenium webdriver':
        i.click()
        break
driver.find_element_by_css_selector('input#google-location-search').send_keys('New York')


time.sleep(5)
driver.quit()

Output:

1
Keyword
selenium
selenium webdriver
serena
Job Title
selenium tester
frontend developer with tableau ,selenium and ui
ivr tester w/selenium
pega cdh experience and selenium automation qa
qa engineer c#, .net, selenium

Process finished with exit code 0

0
09914040666 Replied on 11/02/2021

Hey, 

The issue is of the xpath you are using to extra multiple elements out of the suggestion box. I have updated the file your reference, kindly have a look once.

from selenium import webdriver
import time

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(10)
driver.get("http://www.dice.com/")
wait = WebDriverWait(driver, 10)
driver.find_element_by_css_selector('div#searchInput-div > form > div > div.flex-grow-1.mr-md-2 > div > dhi-new-typeahead-input > div > input').send_keys('Selenium')
time.sleep(5)
options = driver.find_elements_by_xpath("//*[@id='cdk-overlay-0']/div/dhi-typeahead-grouped-list/div/div/div")
print("No. of options : "+str(len(options)))
print("")
for i in options:
    print(i.text)
    if i.text == 'selenium webdriver':
        time.sleep(5)
        i.click()
        break
driver.find_element_by_css_selector('input#google-location-search').send_keys('New York')


# time.sleep(5)
# driver.quit()


G
Gaurav Valera Replied on 17/02/2021

Thanks, please close the ticket


Related Posts