Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
220 views
by The go-to Tester (218 points)
I am automating a page using Selenium Webdriver using Python language. My code is-:

import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
chromedriver = "C:\Selenium driver\chromedriver"
driver = webdriver.Chrome(chromedriver)
driver.maximize_window()
driver.get("http://qxf2.com/selenium-tutorial-main")
menu = driver.find_element_by_xpath("//img[@src='./assets/img/menu.png']")
menu.click()
resource = driver.find_element_by_xpath("//a[text()='Resources']")

Action = ActionChains(driver)
action.move_to_element(resource)
action.perform()
time.sleep(2)
gui_automation = driver.find_element_by_xpath("//a[text()='GUI automation']")
gui_automation.click()
time.sleep(3)
driver.close()

I am getting this error-:

Traceback (most recent call last):
  File "E:\Python Workspace\selenium-beginners-master\selenium-beginners-master\08_Hover.py", line 49, in <module>
    gui_automation.click()
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 77, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 494, in _execute
    return self._parent.execute(command, params)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
ElementNotVisibleException: Message: element not visible
  (Session info: chrome=55.0.2883.87)
  (Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 6.1.7601 SP1 x86_64)

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer

I would suggest you to use WebDriver waits instead of using time.sleep.

Eg.

element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.xpath, "//a[text()='GUI automation']"))
    )

and

do not forget the imports

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...