D
D
Denis99992015-12-26 07:39:03
Python
Denis9999, 2015-12-26 07:39:03

Bug in Python 3 when the code is almost the same?

There are two versions of the code, the first one works, the second one doesn't. The first is a simplified second, I simplified it to identify the error. But the first code works. The difference between them is that in the second option there are transitions, but I have already run out of guesses. The error occurs on the second iteration of the loop, on this line:

t = driver.find_element_by_xpath(".//*[@id='list']/li["+str(i)+"]")

1st:
i = 1
while i < 10:
  t = driver.find_element_by_xpath(".//*[@id='list']/li["+str(i)+"]/a")
  el_text = t.text
  print (el_text)
  i = i + 1

2nd:
i = 1
while i < 6:
  t = driver.find_element_by_xpath(".//*[@id='list']/li["+str(i)+"]")
  el_text = t.text
  driver.find_element_by_tag_name("html").send_keys(Keys.CONTROL + 't')         //открывает новую вкладку - эти комментарии только в этом посте, в коде их нет
  driver.get(el_text)
  driver.find_element_by_tag_name("html").send_keys(Keys.CONTROL + '1')         //переходит на первую
  i = i + 1
  print (i)

Help, please, to solve in what here a problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
throughtheether, 2015-12-26
@throughtheether

Sorry, I didn't understand, did my answer to your previous question help you? If so, why isn't it marked as a solution? If not, why didn't you add specifics to the old post and create a new one?
On the topic of the current question:

t = driver.find_element_by_xpath(".//*[@id='list']/li["+str(i)+"]")
el_text = t.text
driver.get(el_text)

Are you sure el_text contains text that can be interpreted as a URL/URI? I ask because in examples 1) and 2) you use different xpath expressions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question