0

I try to write a short script to search a key word on newspaper's website and an

'ElementNotVisibleException: Message: element not visible' is raised.

I'm not able to fixe it...

Thank you for help

code:

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

    driver = webdriver.Chrome()
    driver.get("https://www.tsa-algerie.com")
    wait = WebDriverWait(driver, 8)
    elem = driver.find_element_by_name("s")
    wait.until(EC.visibility_of_element_located((By.name,"s")))
    elem.send_keys("Algieria")
    elem.send_keys(Keys.RETURN)
    assert "No results found." not in driver.page_source
    driver.close()
    os.system('pause')
Jignasha Royala
  • 1,032
  • 10
  • 27
SAN
  • 11
  • 3
  • 2
    Possible duplicate of [ElementNotVisibleException : Selenium Python](https://stackoverflow.com/questions/47108512/elementnotvisibleexception-selenium-python) – undetected Selenium Jan 10 '18 at 13:36
  • I think you should check the spelling at: elem.send_keys("**Algieria**"). You might have misspelled the word. – muka.gergely Jan 10 '18 at 14:16

2 Answers2

-1

You just made a variable called wait:

wait = WebDriverWait(driver, 8)

But you didn't use it in your code. Try this:

visibility_of_element_located

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

WebDriverWait(driver, 8).until(EC.visibility_of_element_located((By.NAME, "s")))
elem = driver.find_element_by_name("s")

That way script will wait until 's' element appear, then u gonna find this element. Remember about the order. First u wait, next you can use it.

Bonzulo
  • 26
  • 3
-1

This code will help you:

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

driver = webdriver.Chrome()
driver.get("https://www.tsa-algerie.com")
driver.maximize_window()

#To click on Search Icon to open the search box
ele=driver.find_element_by_xpath('//div[@class="template-header__search search__open transition"]/img')
ele.click()

#wait till search text box appear and then enter the desired keyword you want to search
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.NAME, "s")))
elem = driver.find_element_by_name("s")
elem.send_keys("Algieria")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
thebadguy
  • 2,092
  • 1
  • 22
  • 31
  • While this may theoretically answer the question, it would be preferable to explain what this code does and how it answers the question. – JeffC Jan 11 '18 at 21:30
  • @JeffC I just helped him with working code as he was not able to search the desired things on webpage. Added comments to code for better understanding – thebadguy Jan 12 '18 at 03:38