0
votes

Software Details

  1. Operating System: Mac OSX EL Capitan
  2. Eclipse Neon.3 Release (4.6.3)
  3. Python Interpreter: 3.6
  4. Chrome Version: 63.0.3239.132
  5. Chrome Driver Version: ChromeDriver 2.35

When executed below selenium-python code from python IDLE chrome launches gmail.com successfully. Where as when executed from PyDev(Eclipse) chrome launches gmail.com and browser is closed immediately.Please advice what could be the issue and probable solution

from selenium import webdriver
import os
class pySelChrome():
    '''
    classdocs
    '''


    def openChrome(self):
        '''
        Constructor
        '''
        chromeDriverPath = "/Users/XX/Documents/workspace/PySelenium/pySelPack/chromedriver"
        os.environ["webdriver.chrome.driver"]=chromeDriverPath
        os.environ["webdriver.chrome.driver"]="/Users/XX/Documents/workspace/PySelenium/pySelPack/chromedriver"
        driver = webdriver.Chrome(chromeDriverPath)
        driver.get("http://gmail.com")
        driver.implicitly_wait(30)
        driver.fullscreen_window()
        return driver
        

psc = pySelChrome()
psc.openChrome()

But the same code without class definition works fine in PyDev(Eclipse).

from selenium import webdriver
import os

chromeDriverPath = "/Users/XX/Documents/workspace/PySelenium/pySelPack/chromedriver"
os.environ["webdriver.chrome.driver"]=chromeDriverPath
os.environ["webdriver.chrome.driver"]="/Users/XX/Documents/workspace/PySelenium/pySelPack/chromedriver"
driver = webdriver.Chrome(chromeDriverPath)
driver.get("http://gmail.com")
driver.implicitly_wait(30)
driver.fullscreen_window()
2

2 Answers

0
votes

Correct Class definition syntax should be: class ClassName: rather than class CLassName():, remove the ().

And you missed the main() function as the entry if run as script.

if __name__ == "__main__":
    # execute only if run as a script
    psc = pySelChrome()
    psc.openChrome()
0
votes

Same issue even when I removed () from class definition. Also added main method. Please see below code and advice.

from selenium import webdriver
import os



class pySelChrome:
    '''
    classdocs
    '''


    def openChrome(self):
        '''
        Constructor
        '''
        chromeDriverPath = "/Users/XX/Documents/workspace/PySelenium/pySelPack/chromedriver"
        os.environ["webdriver.chrome.driver"]=chromeDriverPath
        os.environ["webdriver.chrome.driver"]="/Users/XX/Documents/workspace/PySelenium/pySelPack/chromedriver"
        driver = webdriver.Chrome(chromeDriverPath)
        driver.get("http://gmail.com")
        driver.implicitly_wait(30)
        driver.fullscreen_window()
        return driver


if __name__ == "__main__":
    # execute only if run as a script
    psc = pySelChrome()
    psc.openChrome()