我的测试代码如下:

def test_12(self):
        self.browser.find_element_by_link_text(u'批改结果').click()
        time.sleep(2)
        area = self.browser.find_element_by_id("select-area")
        time.sleep(1)
        # Select(area).select_by_value('010')
        Select(area).select_by_index(1)
        time.sleep(2)

用 firebug 查看元素如下图

执行后的报错如下:

Error
Traceback (most recent call last):
  File "C:\E\Users\Administrator\PycharmProjects\IPSWeb\Test\Test_IPSTutor\TestScripts.py", line 68, in test_12
    area = self.browser.find_element_by_id("select-area")
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 266, in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 744, in find_element
    {'using': by, 'value': value})['value']
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 233, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"select-area"}
  (Session info: chrome=51.0.2704.103)
  (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 10.0 x86_64)

之前有别的下拉选择我都定位成功了啊,这个不知道为什么一直报错?selector 不能通过 id 定位么?改 css 什么的也都不对啊,望牛人帮我看看问题出在哪里了


↙↙↙阅读原文可查看相关链接,并与作者交流