English 中文(简体)
索引:范围外清单
原标题:IndexError: list index out of range

I m new to selenium python. right now i m trying to run python code that already converted from selenium Ide. when i m ran the code i got this error. i m using eclipse to run the code

ERROR: test_isnin2 (__main__.Isnin2)

======================================================================
ERROR: test_isnin2 (__main__.Isnin2)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:EclipseWorkspacescsse120pythonsrcIsnin2.py", line 20, in test_isnin2
    driver.get("/search?q=google&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a")
  File "C:Program FilesPython27libsite-packagesselenium-2.4.0-py2.7.eggseleniumwebdriver
emotewebdriver.py", line 154, in get
    self.execute(Command.GET, { url : url})
  File "C:Program FilesPython27libsite-packagesselenium-2.4.0-py2.7.eggseleniumwebdriver
emotewebdriver.py", line 144, in execute
    self.error_handler.check_response(response)
  File "C:Program FilesPython27libsite-packagesselenium-2.4.0-py2.7.eggseleniumwebdriver
emoteerrorhandler.py", line 111, in check_response
    zeroeth = value[ stackTrace ][0]
IndexError: list index out of range

----------------------------------------------------------------------
Ran 1 test in 35.406s

FAILED (errors=1)

我的发言如下:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re

class Isnin2(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "http://www.google.com.my/"
        self.verificationErrors = []

    def test_isnin2(self):
        driver = self.driver
        driver.get("/search?q=google&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a")
        driver.find_element_by_css_selector("em").click()
        driver.find_element_by_id("lst-ib").click()
        driver.find_element_by_id("lst-ib").clear()
        driver.find_element_by_id("lst-ib").send_keys("selenium python")
        driver.find_element_by_link_text("Setting Up Selenium with Python").click()
        driver.find_element_by_link_text("selenium.py").click()

    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException, e: return False
        return True

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

i 真正希望有人能够帮助我,因为一滴新东西可以 se。

问题回答

似乎你不向<代码>driver<>/code>提供<>base_url。 或许你应当取代这一行文:

driver.get("/search?q=google&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a")

具有类似内容:

driver.get(self.base_url + "/search?q=google&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a")

www.un.org/Depts/DGACM/index_spanish.htm

另外,你是否想用<代码>is_element_present方法测试一些东西? 有了“灰色体”试验框架,方法名称必须从test开始。 因此,如果你希望将其改名为的测试_is_element_present

此外: 如果你计划对答复进行多次测试,那么你应将<代码>driver.get(>打电话到setUp方法中,因为测试的顺序不一定与你写的测试顺序相同。 另一方面,在要求进行任何测试之前,可保证操作。

如果我可以的话,我就对康斯坦丁斯的答复发表意见,但我没有回过。

我将这一问题作为审视民主选举学会的借口——像上述守则一样,对波德维埃的出口非常直接,在我的测试案例中,它导致了同样的恶性。

斯坦丁斯提到的其他问题是由于民主选举学会能力有限所致。 即:现行方法视之为国际民主和选举援助学会正在进行的工作的一部分,我猜测自己是实际检查的持有人。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签