0

I want to check the innertext of a web element, but xpath does not find it even if i gave it the absolute path. I get no such element error on the line where i try to define Plaje

from selenium import webdriver
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.Edge("D:\pariuri\python\MicrosoftWebDriver.exe")

driver.get("https://www.unibet.ro/betting#filter/all/all/all/all/in-play")

try:
    element_present = EC.presence_of_element_located((By.CLASS_NAME, 'KambiBC-event-result__score-list'))
    WebDriverWait(driver, 4).until(element_present)
except TimeoutException:
    print ('Timed out waiting for page to load') 

event = driver.find_elements_by_class_name('KambiBC-event-item KambiBC-event-item--type-match') 

for items in event:
   link = items.find_element_by_class_name('KambiBC-event-item__link')
   scoruri =  items.find_element_by_class_name('KambiBC-event-item__score-container') 

   scor1 =  scoruri.find_element_by_xpath(".//li[@class='KambiBC-event-result__match']/span[1]")
   scor2 =  scoruri.find_element_by_xpath(".//li[@class='KambiBC-event-result__match']/span[2]")

   print (scor1.text)
   print (scor2.text)
   if scor1.text == '0' and scor2.text == '0':

        link.click()
        Plaje = driver.find_element_by_xpath(".//*[@id='KambiBC-contentWrapper__bottom']/div/div/div/div/div[2]/div[2]/div[3]/div/div/div[4]/div[1]/div[4]/div[2]/div/div/ul/li[2]/ul/li[6]/div[1]/h3")
        print (Plaje.text)

enter image description here

1
  • //h3[@class="KambiBC-bet-offer-subcategory__label js-bet-offer-subcategory-label"]/text() use this xpath Commented Aug 30, 2017 at 10:34

3 Answers 3

1
  1. Always add some implicit wait after initiating the webdriver.

    driver = webdriver.Firefox()
    driver.implicitly_wait(10) # seconds
    
  2. Try with the below xpath.

    "//h3[contains(text(),'Total goluri']"
    

    or

    "//div[@class='KambiBC-bet-offer-subcategory__container']/h3[1]"
    

Hope this helps. Thanks.

EDIT: Its always advisable to use the implicit wait. We can handle the same using the explicit wait also. But we need to add the explicit wait for each and every element. Also there is a good change you might miss adding explicit wait to few elements and debug again. The choice is yours always.

Sign up to request clarification or add additional context in comments.

9 Comments

Here i have identified the element using its inner text. If the objective is to find the innertext of that element, Can you share me the complete html DOM so that i can help you with some other xpath ways.
@ santhosh kumar to be honest i do not know how to give you the complete html DOM as it is to big to add as comment here.
Dude,, create a gist with the html code and share the gist link.
Interesting when i tried your answer i got the same error " no such element", but then i inserted the line you suggested driver.implicitly_wait(10) and it now works, but i read in the Selenium documentaion that the webdriver will wait for the page to load. Anyway glad it works now
Implicit wait doesn't wait for the page to load. It actually waits till the time for the availability of the web elements.
|
0

try using .get_attriute("value") or .get_attribute("innerHTML") instead of .text

Comments

0

Try below :

//h3[contains(.,'Total goluri')]

hope it will help you :)

Comments

Your Answer

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.