-1

I think my question is somehow related to this post Selenium - cannot click on an element inside a modal

I click on a an element and it opens a modal table. Then, I would like to select a particular checknox in a long list but Selenium gives me back an error.

That's what I did:

I tested first with Selenium IDE: first I recorded the operations but when I try to replay them in the log I get this:

Running 'Step2_sele'
1.open on /reserve-space/... OK
2.click on css=a[title="Locations"] > span... OK
3.click on linkText=Add/Remove Locations... OK
4.Trying to find xpath=//input[@value='2427']... Failed:
Element is not currently visible and may not be manipulated

I thought I should have given more time to the element to show up and I wrote this with Python

browser = webdriver.Chrome()
browser.get(url_res)
time.sleep(10)
browser.find_element_by_css_selector('a[title="Locations"]>span').click()
time.sleep(10)
browser.find_element_by_css_selector('a.dynamic-filter-item-add.summary').click()
time.sleep(10)
browser.find_element_by_xpath("xpath=//input[@value='2427']").click()

But I get this other error

Traceback (most recent call last):
  File "bot.py", line 69, in <module>
    browser.find_element_by_xpath("xpath=//input[@value='2427']").click()
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 393, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 966, in find_element
    'value': value})['value']
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression xpath=//input[@value='2427'] because of the following error:
TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type.
  (Session info: chrome=69.0.3497.100)
  (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.16299 x86_64)

This is a screenshot of how the html code look like because I cannot post the real url enter image description here

2
  • 1
    Why did you add "xpath=" to your XPath? What do you think it should do? Commented Oct 4, 2018 at 17:56
  • I'm very new to Selenium and HTML, I think I have done some cut and paste from the wrong example. I don't see any other explanation! Commented Oct 4, 2018 at 21:31

1 Answer 1

1

I assume the xpath string causes the problem. If my assumption is correction, the following should work:

browser.find_element_by_xpath("//input[@value='2427']").click()
Sign up to request clarification or add additional context in comments.

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.