Friday, February 13, 2015

Ascending orders of a list

def element(x):
    first_element = x[0]
    for i in range(0, len(x)):
        if first_element <= x[i]:
            pass
        else:
            first_element = x[i]
    return first_element

def ascending(y):
    new_list = []
    old_list = y
    for i in range(0,len(y)):
        small = element(y)
        new_list.append(small)
        old_list.remove(small)
    return new_list[-2]

#print ascending([5,25,41,8,-35,-63,-0.25,21])

Program 2:

__author__ = 'valli_000'

def bubblesortdescending(list):
    length = len(list)
    count = length-1
    while count > 0:
        for i in range(length-1):
            if list[i] <= list[i+1]:
                temp = list[i]
                list[i] = list[i+1]
                list[i+1]=temp
                #print list
            else:
                pass
        count= count - 1
    return list

def bubblesortascending(list):
    length = len(list)
    count = length-1
    while count > 0:
        for i in range(length-1):
            if list[i] <= list[i+1]:
                pass
                #print list
            else:
                temp = list[i]
                list[i] = list[i+1]
                list[i+1]=temp
        count= count - 1
    return list



print bubblesortdescending([119, 1, 9, 7, 3, 10, 13, 15, 8, 12])
print bubblesortascending([119, 1, 9, 7, 3, 10, 13, 15, 8, 12])



Sunday, February 8, 2015

Python Selenium Notes

Python Selenium notes:

Case 1:
Sometimes identified the element using xpath works fine with the selenium IDE, but not with the webdriver ( or via python script)

Solution:
Then its not the problem of the xpath element.

The problem with the webpage framing.We should move to the respective frame first and then use the xpath.

Eg;
driver.switch_to_frame(driver.find_element_by_tag_name("iframe"))
driver.find_element_by_xpath("ENTER THE XPATH HERE")
-----------------------------------------------------------------------------------------------------
Case 2:
After case 1, how to back to the default frame to access the other elements?

Solution:
driver.switch_to_default_content()
-------------------------------------------------------------------------------------------------------
Case 3:
Mouse over command in python

Solution:

product = driver.find_element_by_link_text("Products")
Hover = ActionChains(driver).move_to_element(product)
Hover.perform()
-------------------------------------------------------------------------------------------------------
Case 4:
Access variable of one function from another function in a class without using __init__ method

Solution with example:

class Testclass():
    #a = "vallinayagam"
 
    def method_one(self):
        a = "valli"
        return a
     

    def method_two(self):
        print self.method_one()
     
ba = Testclass()
ba.method_two()
------------------------------------------------------------------------------------------------------
Case 5:
Xpath filter commands:

For below HTML,






in the <td, we can access the values for class, data-year, data-month using below command

1. First identify the xpath  by rightclick -> Copy XML and filter t using "data-month]

 xpath path  =//div[5]/div/table/tbody/tr/td[5]
 Filter = [@data-month='2']

To locate element using xpath = "xpath=//div[5]/div/table/tbody/tr/td[5][@data-month='2']"

Case 6:
How to select a value from dropdown box?








Solution:
Step 1: Identify the ID and value from the options tag. you want?

code:
set = driver.find_element_by_id('ctl00_ctl00_body_PrintContent_IWOVID_item_1_ddlCountries')

for option in set.find_elements_by_tag_name('option'):
if option.text == 'India':
option.click()
break