Aug-29-2018, 02:33 PM
This is a small code segment of a program and below the output is given -
And if the following line
try: print('li 8') lim = driver.find_element_by_xpath('//*[@id="names_load_paginate"]/ul/li[8]/a').text except: lim = 6 while lim >= 2: print(lim) list_string = '//*[@id="names_load_paginate"]/ul/li[' + str(lim) + ']/a' try: print(lim) lim = driver.find_element_by_xpath(list_string).text print(lim) break except: print("ex lim") lim = lim - 1For this code segment I am getting the below output -
Output:li 8
6
6
ex lim
5
5
ex lim
4
4
ex lim
3
3
I don't understand why the code is stopped executing at 'lim = 3', though it should raise an exception for 'lim = 3' and continue then to stop at "lim = 2" because XPATH - "//*[@id="names_load_paginate"]/ul/li[2]/a" is present only in the web page no any other list element are present there. And if the following line
lim = driver.find_element_by_xpath(list_string).textexecuted for lim = 3 then three values should be printed, because there is a print statement after the above mentioned line which is missing in output. Please share your views.