0
votes

I am locating an element on http://ntry.com/#/stats/ladder/round.php, but I keep failing locating it, after trying several ways, including ind_element_by_css_selector, ind_element_by_xpath... and so on.

Even though I used WebDriverWait, I keep failing. What would be the Problem?

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
from selenium.webdriver import ActionChains

driver = webdriver.Firefox()
driver.get("http://ntry.com/#/stats/ladder/round.php")

try:
   element = EC.presence_of_element_located((By.XPATH, '//div[@id="analysis-table"]/div[1]/div[1]/p[1]/span[1]/strong'))

   #or element = WebDriverWait(driver, 30).until(
       EC.presence_of_element_located((By.CSS_SELECTOR, "#analysis-table>div.bar_graph>div:nth-child(1)>p.left.on>span.per>strong"))
   )
except:
   print "HIJUDE"

driver.quit()

I used Implicit wait, but that also makes same error. Not using Wait makes NoSuchElementException too.

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":'//div[@id="analysis-table"]/div[1]/div[1]/p[1]/span[1]/strong'}

Is the website related with being unable to find the Element? or using method other than Xpath or css_selector would do? I am pretty confused why this happened.

-------------Edit-------------- I found out that there is iframe at the upper xpath level of div[@id="analysis-table"]. I guess that's the reason. Should I always use driver.switch_to_frame() in this case? Btw, is driver.switch_to_window() different from frame()?

1
What is .on on p.left.on? I don't see an "on" class... - dyeray
I found that the class names become different time to time, because this site is dynamic webpage. but using Xpath above seem to be always valid. - heyzude
Yes, if you have an iframe element you will need to switch to the frame and then it should be able to find the element. - DarthOpto
Yes, switing to iframe using driver.switch_to_frame() worked. Thanks! - heyzude

1 Answers

0
votes

You have a problem in p.left.on in the path. One element has single class left and the other one classes right and on. It should be

"#analysis-table>div.bar_graph>div:nth-child(1)>p.left>span.per>strong"

Or

"#analysis-table>div.bar_graph>div:nth-child(1)>p.right.on>span.per>strong"