0

I am new to selenium, I tried using implicit wait condition and wait until but it is of no use.But it is working fine when it is executed individually.

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait

browser=webdriver.Firefox()
browser.get('https://runningstatus.in')
i=0

element = WebDriverWait(browser, 10)
select=Select(browser.find_element_by_id('godate'))
select.select_by_index(i)
browser.find_element_by_tag_name('input').send_keys('12801',Keys.RETURN)

x=browser.find_element_by_css_selector('div.runningstatus-widget-content')
name=x.find_element_by_tag_name('p')

print name.text
jatin rajani
  • 495
  • 1
  • 6
  • 15
  • Possible duplicate of [Selenium "selenium.common.exceptions.NoSuchElementException" when using Chrome](https://stackoverflow.com/questions/47993443/selenium-selenium-common-exceptions-nosuchelementexception-when-using-chrome) – undetected Selenium Jan 29 '18 at 16:32

1 Answers1

0

Any time a page transition occurs, or a new element is expected to appear, you should wait for it to exist in the DOM. If you don't, you'll get frequent timeouts. In your case, try the following...

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

browser=webdriver.Firefox()
browser.get('https://runningstatus.in')
i=0

element = WebDriverWait(browser, 10)
select=Select(browser.find_element_by_id('godate'))
select.select_by_index(i)
browser.find_element_by_tag_name('input').send_keys('12801',Keys.RETURN)

css = 'div.runningstatus-widget-content'
x = WebDriverWait(browser, 30).until(
    EC.element_to_be_clickable(('css selector', css)))

print x.text
Ron Norris
  • 2,642
  • 1
  • 9
  • 13
  • Thank you very much @Ron Norris – jatin rajani Jan 29 '18 at 16:48
  • Still, it is showing the same error.When i tried this, name=x.find_element_by_tag_name('p') – jatin rajani Jan 29 '18 at 16:57
  • Not sure then why it's not working for you. This worked on my system all the way through the print statement. This was my command line output: `Live Running Train Status` and `Enter Train Number:` – Ron Norris Jan 29 '18 at 17:00
  • But i want to access the p tag,and that is returning an error. – jatin rajani Jan 29 '18 at 17:42
  • The short answer is that the x element has no

    children. So in your original code, `name=x.find_element_by_tag_name('p')` will throw an exception because there are no

    elements within x. So I believe the selector you're using to find x is not what you really want. Looking for the

    tag is the correct process, if x had a

    element.

    – Ron Norris Jan 29 '18 at 18:57