0

I'm working on a project to extract some data from a website. In this website there is search form that I should fill it. One of the inputs which is text, shows a suggestion after entering 2 or 3 characters and I should select that option in order to go forward or search button will be activated. The problem is that when I use the following code:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='LocationSuggestionBox']/ul/div/li/div"))).click()

I modified the xpath in above code. The actual xpath is as fllow:

//*[@id="LocationSuggestionBox""]/ul/div/li/div

But I don't know how to add it in my code to not get the syntax error.

The final result with my working code is :

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='LocationSuggestionBox']/ul/div/li/div"))).click()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
4
  • 2
    Could you post what the HTML on the page looks like when you are trying to click the suggestion option? This code looks fine but it is hard to tell what is wrong without any context from the page you are testing. From the TimeoutException, it looks like the wait is timing out because the EC.element_to_be_clickable condition is never met. Commented Sep 26, 2019 at 16:22
  • The webpage is locatr.cloudapps.cisco.com/WWChannels/LOCATR/… I want to fill the form and search based on that. But When I enter the name of location, suggestion box appears and the mentioned problem occurs. Commented Sep 26, 2019 at 16:37
  • Which element you want to click? Commented Sep 26, 2019 at 16:40
  • for example type china in location box and then suggestionbox appears behind that. I want to click on that in order have something in my location textbox. Commented Sep 26, 2019 at 16:42

2 Answers 2

1

Your XPath is returning NULL when I run against the page, so the selector is incorrect here.

Based on the page info you provided, here's a correct selector:

"//li[div/span[text()='" + locationNameHere + "']]"

So you can change your code to:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//li[div/span[text()='" + locationNameHere + "']]"))).click()

If you just want to click the first location suggestion, you can use this:

//li[div/span]

But this XPath will get you a list of ALL visible location suggestions.

Sign up to request clarification or add additional context in comments.

2 Comments

I used copy xpath from google chrome, and because I used chromdriver I thought that my code was correct
sometimes the selectors from chrome xpath are not always correct. I use an XPath chrome extension to test mine out, which is how I was able to write a new one for you. You can install it if you want chrome.google.com/webstore/detail/xpath-helper/…
1

Induce WebDriverWait and element_to_be_clickable() And following xpath.

driver.get('https://locatr.cloudapps.cisco.com/WWChannels/LOCATR/openBasicSearch.do;jsessionid=8CDF9284D014CFF911CB8E6F81812619')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='searchLocationInput']"))).send_keys('China')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//li[@class='ng-scope']//span[text()='CHINA']"))).click()

Browser snapshot:

enter image description here

1 Comment

It needs to know the result of suggestionbox

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.