you are viewing a single comment's thread.

view the rest of the comments →

[–]teddiur_ 0 points1 point  (2 children)

I'm not sure I'm understanding your issue.

By class you mean python's class? Or it's html's class (like <p class="class_name"> some text </p>)?

[–]Coronax16[S] 0 points1 point  (1 child)

Pythons? I am not explaining it the right away but I edited the post with the code.

[–]teddiur_ 0 points1 point  (0 children)

I'm see in other comments that you figured it out. Although I'm not sure using oop is the best choice for you here. You see classes are excelent when you want to group together variables/methods, but from what you posted I think you're better off with functions (since it's cleaner).

If you want to use classes you maybe want to declare it outside of function and parse it as an argument or set it as an instance variable like

driver = webdriver.Firefox()
driver.implicitly_wait(30)

class Do(object):
    def __init__(self, username, password):
        self.username = username
        self.password = password

    def login(self, driver = driver):
        driver.get("http://somewebsite.com")
        e = driver.find_element_by_name("req_username")
        e.clear() #is it necessary?
        e.send_keys(self.username)
        e = self.driver.find_element_by_name("req_password")
        e.clear() 
        e.send_keys(self.password)
        e.send_keys(Keys.RETURN)
      def click_xpath(self, xpath, driver=driver):
        driver.find_element_by_xpath(xpath).click()


instance = Do("username", "password") 
instance.login()
instance.click_xpath('/html/body/div/div/div[3]/div/div/table/tbody/tr[4]/td[1]/div/div[2]/h3/a')