0

enter image description here

I am trying to automate login on a website using selenium. (Windows 10 64 bit os)

Using the below code I am able to open a link, But once webpage loads the get cmd does not release my python interpreter next cmd:

browser.find_element_by_class_name('gb_g').click()

does not run.

I tried to open google.com but the issue is same, I tried different browser it works but my project URL only works with internet explorer.

I have tried with both 64 & 32-bit driver version of internet explorer

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

link = 'https://www.google.com/'
browser = webdriver.Ie(executable_path='S:\work\Automation\Elog\IEDriverServer.exe')
browser.get(link)
browser.find_element_by_class_name('gb_g').click()
  • Can you please inform us why you are trying to run IEDriverServer with FireFox? I suggest you to try to run it with Internet Explorer. Also try to check and make sure that you are using the latest version of IEDriverServer. – Deepak-MSFT Dec 20 '19 at 14:37
  • Before asking the question I tried to use firefox browser to check, so while pasting here I fail edit code. – rahul desai Dec 21 '19 at 07:26

1 Answers1

0

You need to consider a few things:

  • If your use case is to use you need to use IEDriverServer.exe through selenium.webdriver.ie.webdriver.WebDriver() Class as follows:

    webdriver.Ie(executable_path=r'S:\path\to\IEDriverServer.exe')
    

To click() on the element with text as Gmail you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using LINK_TEXT:

    from selenium import webdriver
    
    browser = webdriver.Ie(executable_path=r'S:\work\Automation\Elog\IEDriverServer.exe')
    browser.get("https://www.google.com/")
    WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.LINK_TEXT, "Gmail"))).click()
    
  • Using CSS_SELECTOR:

    from selenium import webdriver
    
    browser = webdriver.Ie(executable_path=r'S:\work\Automation\Elog\IEDriverServer.exe')
    browser.get("https://www.google.com/")       
    WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"a.gb_g[href*='com/mail/?tab']"))).click()
    
  • Using XPATH:

    from selenium import webdriver
    
    browser = webdriver.Ie(executable_path=r'S:\work\Automation\Elog\IEDriverServer.exe')
    browser.get("https://www.google.com/")
    WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.XPATH,"//a[text()='Gmail']"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

Update (from @rahuldesai's comment)

With the above mentioned configurations and using the 32 bit IEDriverServer binary some how the issue gets fixed.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Hi @DebanjanB, the problem is with get() command it freezes the interpreter it opens requested webpage but does not release interpreter so than next command can execute – rahul desai Dec 20 '19 at 11:41
  • What exactly do you mean by _does not release interpreter_? – undetected Selenium Dec 20 '19 at 11:42
  • get() cmd keeps running even after loading the webpage, I have added an image for reference – rahul desai Dec 20 '19 at 12:08
  • Check my answer, you need to induce _WebDriverWait_ for `document.ready` state as **complete** first for `get()` to be completed. – undetected Selenium Dec 20 '19 at 12:10
  • @rahul desai -- Run this python code above in PyCharm or execute it from the command line. Here is a link to download PyCharm. Jupyter is cool and all but for this try PyCharm. – Jortega Dec 20 '19 at 12:58
  • @rahuldesai Checkout the updated answer and let me know the status. – undetected Selenium Dec 20 '19 at 13:07
  • I tried with Pycharm and Spyder both IDE but it did not help. Also reinstalled selenium still same problem – rahul desai Dec 21 '19 at 07:28
  • Tried using 32-bit Ie driver shomhow resolved the issue. – rahul desai Dec 23 '19 at 16:51
  • Thanks for sharing the solution for the issue. I suggest you post your solution as an answer for this thread and try to mark your own answer as an accepted answer for this question after 48 hrs when it is available to mark. It can help other community members in the future in similar kinds of issues. Thanks for your understanding. – Deepak-MSFT Dec 24 '19 at 10:54
  • @rahuldesai I have update the answer with your comments which solves the issue. – undetected Selenium Dec 24 '19 at 11:11