0

I'm trying to click an options from a website dropdown menu but I am not able to click.

I am using "xpath" locators for the element and I upgraded my chrome to the latest version for chromedriver.

I am using:

  • chrome=68.0.3440.106
  • chromedriver=2.41.578700
  • platform=Linux 4.15.0-30

Code snippet that contains error line:

 def test_adsz(self):
 driver = self.driver
 driver.get("url")
 driver.find_element_by_xpath("//img[@alt='Dersomani']").click()
 driver.find_element_by_xpath(u"(//a[contains(text(),'Sınıf')])[2]").click()
 driver.find_element_by_xpath(u"(//a[contains(text(),'ÜYE GİRİŞİ')])[2]").click()
 driver.find_element_by_name("email").clear()
 driver.find_element_by_name("email").send_keys("admin")
 driver.find_element_by_name("password").clear()
 driver.find_element_by_name("password").send_keys("12345")
 driver.find_element_by_xpath(u"(.//*[normalize-space(text()) and normalize-space(.)='alın'])[1]/following::button[1]").click()
 driver.find_element_by_xpath("//img[@alt='User Name']").click()
 driver.find_element_by_xpath(u"(//a[contains(text(),'Yönetici')])[2]").click()
 driver.find_element_by_link_text(u"Üye Listesi").click()
 driver.find_element_by_xpath(u"(.//*[normalize-space(text()) and normalize-space(.)='Tanım İşlemleri'])[1]/following::span[1]").click()
 driver.find_element_by_link_text("Profilim").click()
 driver.find_element_by_xpath("//div[@id='logged_in']/a").click()
 driver.find_element_by_xpath(u"(//a[contains(text(),'Çıkış Yap')])[2]").click() 

My error line:

 driver.find_element_by_xpath(u"(//a[contains(text(),'Sınıf')])[2]").click()

My traceback info:

traceback (most recent call last):
driver.find_element_by_xpath(u"(//a[contains(text(),'Sınıf')]) 
[2]").click()
File "/usr/local/lib/python2.7/dist- 
packages/selenium/webdriver/remote/webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "/usr/local/lib/python2.7/dist- 
packages/selenium/webdriver/remote/webelement.py", line 628, in 
_execute
return self._parent.execute(command, params)
File "/usr/local/lib/python2.7/dist- 
packages/selenium/webdriver/remote/webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist- 
packages/selenium/webdriver/remote/errorhandler.py", line 242, in 
check_response
raise exception_class(message, screen, stacktrace)
ElementNotVisibleException: Message: element not visible`

Thanks in advance.

asked Aug 15, 2018 at 8:35
12
  • sqa.stackexchange.com/questions/33880/… or stackoverflow.com/questions/27927964/… may be related / help you Commented Aug 15, 2018 at 8:44
  • share some code that produces the issue. Commented Aug 15, 2018 at 9:23
  • I've added the code snippet and the error line. @AlexeyR. Commented Aug 15, 2018 at 10:47
  • but due to the error you have posted, your error line is driver.find_element_by_xpath(u"(//a[contains(text(),'1. Sınıf')]) [2]").click() however you mention line driver.find_element_by_xpath(u"(//a[contains(text(),'Sınıf')])[2]").click(). So eventually which line does produce the error? Commented Aug 15, 2018 at 11:10
  • I edited traceback info area. Error line is driver.find_element_by_xpath(u"(//a[contains(text(),'Sınıf')])[2]").click() @AlexeyR. Commented Aug 15, 2018 at 11:17

1 Answer 1

0

You should find the reason why the element is not visible at that point. Is the element marked as display:none or hidden by a hide element class? Or maybe is it not visible because there's some other element on top of it or out of visible page borders?

Anyway for the first case where it is somehow marked as hidden you should make it visible. This can be done with javascript. Try this method before clicking on your element:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].style.display='initial';",element);

You can also use

js.executeScript("arguments[0].style.display='visible';",element);

but i find "initial" work more efficiently most of the time. You may need to perform this action to the parent element if this is the one being hidden.

In the second case you should probably use something like this before click:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView(true);" + "window.scrollBy(0,-100);", element);

The "window.scrollBy(0,-100);" is mandatory argument for firefox browser but optional for chrome.

answered Aug 27, 2018 at 10:54
2
  • Thank you @gmitsios but I am using selenium with Python not Java. Commented Aug 28, 2018 at 7:13
  • Ok use driver.execute_script(javascript code here) then instead of js.executeScript(). The rest is javascript which remains the same. Commented Aug 28, 2018 at 7:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.