0

Please, how can I get text "There is no event, try later." from this html?

...</option></select><!-- --></div><div class="media_container__no-match-tracker"><div><div><div class="icon icon--football icon--size_auto"></div><div class="icon icon--volleyball icon--size_auto"></div><div class="icon icon--handball icon--size_auto"></div><div class="icon icon--hockey icon--size_auto"></div><div class="icon icon--basketball icon--size_auto"></div><div class="icon icon--tennis icon--size_auto"></div></div> There is no event, try later. </div></div></div></div></div><div class="app_column__bottom_row" data-v-eb1959b8=""><div class="app_column__bottom_row_wrapper" data-v-eb1959b8=""><div class="app_column__bottom_row_content" data-v-eb1959b8=""><div class="tab_menu chatMenu" data-v-4d018892="" data-v-eb1959b8=""><div ...

I try:

driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[2]/div/div/div[1]/div/div[2]/div[2]/div')

but return only:

<selenium.webdriver.remote.webelement.WebElement (session="d79e3bdd44586c81ae5922410f0c20dd", element="405526fe-7e1a-4552-af5a-70cfb341e129")>

I use python3, selenium, bs4, headless chrome. Thank you.

314mip
  • 383
  • 1
  • 4
  • 13

2 Answers2

1

A bit hard to read your code and html but try this xpath locator:

//div[@class='media_container__no-match-tracker']

And to return the text of the element:

driver.find_element_by_xpath('//div[@class="media_container__no-match-tracker"]').text
DMart
  • 2,401
  • 1
  • 14
  • 19
0

@DMart

Thank you, this is what I need. Can I one more question? Site is dynamical, so this element is not in code everityme I scrape it. When it doesnt, thist driver.find... return:

        driver.find_element_by_xpath('//div[@class="media_container__no-match-tracker"]').text
Traceback (most recent call last):



  File "<ipython-input-95-8dcfa123bd2a>", line 1, in <module>
    driver.find_element_by_xpath('//div[@class="media_container__no-match-tracker"]').text

  File "C:\Users\Miro\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)

  File "C:\Users\Miro\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
    'value': value})['value']

  File "C:\Users\Miro\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)

  File "C:\Users\Miro\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)

NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class="media_container__no-match-tracker"]"}
  (Session info: headless chrome=86.0.4240.193)

How I can use this as condition? If element is on the site print it, if not print("element isnt on this url").

314mip
  • 383
  • 1
  • 4
  • 13