naa-G
naa-G

Reputation: 11

How to execute testcases through Python Class using Selenium

So I'm trying to build a bot with python and selenium this is my code

from selenium import webdriver
import os
import time

class InstagramBot:

    def __init__(self, username, password):
        self.username = username
        self.password = password
        self.driver = webdriver.Chrome(executable_path='./chromedriver.exe')
        self.driver.get('https://www.Instagram.com/')

The problem is nothing will happen when I try the python bot.py I've tried py bot.py too it didin't throw any errors but the commands really do nothing

please can someone help me findout what the problem is???

I've tried driver = webdriver.chrome ... outside the class and it works but when i put it in the InstagramBot class it wont work

im using python3.6.5 and ive tried other python versions too it didint help

Upvotes: 1

Views: 136

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193318

You were close enough. As you have defined the Class, now you simply need to create an instance so the constructor gets executed calling it from the main as follows:

from selenium import webdriver
import os
import time

class InstagramBot:

    def __init__(self, username, password):
    self.username = username
    self.password = password
    self.driver = webdriver.Chrome(executable_path='./chromedriver.exe')
    self.driver.get('https://www.Instagram.com/')

InstagramBot("naa-G", "naa-G")

Upvotes: 1

Related Questions