Selenium-python2.7:单击模式 table 复选框(在 Selenium IDE 之后)

Selenium-python2.7: click on a modal table checkbox (following Selenium IDE)

我认为我的问题与此有关 post

我点击了一个元素,它打开了一个模式 table。然后,我想 select 一个长列表中的特定 checknox,但 Selenium 返回一个错误。

我就是这么做的:

我首先使用 Selenium IDE 进行了测试:首先我记录了这些操作,但是当我尝试在日志中重播它们时,我得到了这个:

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

我想我应该给这个元素更多的时间来出现,我用 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()

但是我遇到了另一个错误

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)

这是 html 代码的截图,因为我无法 post 真正的 url

我假设 xpath 字符串导致了问题。如果我的假设是更正,则以下应该有效:

browser.find_element_by_xpath("//input[@value='2427']").click()