0

I am trying to fill up an autocomplete zipcode / town form. Even if you input the whole zipcode / town in once you still must validate the autocomplete search (just under the input).I do not put the whole error messages for each attempt otherwise my post would be too long (I put a number for each attempt and --> to show the corresponding result).

the input:

ville = 31000 Toulouse
geo = driver.find_element_by_id("location_p")  
geo.send_keys(ville) 

from here starts the issue: Here is the line making pbs:

<li data-region="16" data-dpt-code="31" class="selected">
<span class="city" title="Toulouse">Toulouse</span>&nbsp;
<span class="zipcode">31000</span>
</li>   

1.

validate = driver.find_element_by_xpath("//li[@class='selected'][contains(.,'data-dpt-code')]")
validate.click() 

--> unable to locate element

2.

validate = driver.find_element_by_css_selector("li.selected") 
validate.click()

--> <exception str() failed>

but

validate = driver.find_element_by_css_selector("li.selected")
assertTrue(validate_is_displayed() and validate_is_enabled())
validate.click()

-> unable to locate element

3. from this : How to handle autocomplete list in webdriver?, I tried:

geo.send_keys(Keys.TAB) 
geo.send_keys(Keys.TAB) 
geo.send_keys(Keys.DOWN) 

-> no error, but the zipcode / town is not validated

4.from Selenium Python - select from autosuggest dropdown, tried

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

 wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@class='selected']/span[@class='city][contains(.,'Toulouse')]"

-> idem as 3

5.from Selenium in Python How use a If - else code if an element is not present, I tried:

elem = driver.find_element_by_xpath('//*[@class="selected"][contains(.,"data-dpt-code")]')
valid = driver.find_element_by_xpath('//span[@class="city"][contains(.,"Toulouse")]')
if valid.is_displayed():
elem.click()

-> selenium.common.exceptions.WebDriverException: Message: Element is not clickable at point (309.5, 9.75). Other element would receive the click: <section class="content-center clearfix"></section>

I need your help folks!! Thanx in advance

2
  • Did you try send_keys(Keys.RETURN) to confirm auto-suggestion? Commented Jan 20, 2019 at 13:33
  • <li data-region="16" data-dpt-code="31" ... looks dynamic. Update the question with more of the outerHTML Commented Jan 21, 2019 at 2:02

3 Answers 3

0

From this error it looks like element is not located on the screen: selenium.common.exceptions.WebDriverException: Message: Element is not clickable at point (309.5, 9.75). Other element would receive the click: <section class="content-center clearfix"></section>

Did you try to use Action chains and move to that element before you click ?

from selenium.webdriver.common.action_chains import ActionChains

ActionChains(driver).move_to_element(your_element).click().perform()
Sign up to request clarification or add additional context in comments.

3 Comments

@Andersson - does not change anything.
@cieunteung - does not change anything
I tried this way: mouse = webdriver.ActionChains(driver)</br> element = driver.find_element_by_xpath('//*[@class="selected"][contains(.,"data-dpt-code")]') </br> mouse.move_to_element(element).perform() </br> but this does not solve the problem. Now, I can see that there is an outer square just above the square I was trying to click in. I guess this outer square is the one to work on. I will get back to you just to let you know. Many thanx guys.
0

using WebdriverWait try clicking the li element

wait(driver, 10).until(
    EC.element_to_be_clickable((By.XPATH, '//li[@class="selected" and contains(., "Toulouse")]'))
).click()

also try with different condition like presence_of_element_located or visibility_of_element_located

Comments

0

I finally had to work with chrome and chromedriver:

WebDriverWait(driver, 
10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,".location-list > 
li:nth-child(1)"))).click()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.