1

I have below program to take screenshot via selenium

    from selenium import webdriver
    from selenium.common.exceptions import TimeoutException
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    driver = webdriver.Chrome(executable_path='C:\Downloadsnew\chromedriver_win32\chromedriver.exe')
    driver.maximize_window()
    #driver.implicitly_wait(40)
    driver.get("https://now.com/welcome.do")
    #element=WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.id,'user_name')))
    elem = driver.find_element_by_id("user_name")
    elem.send_keys("user1")
    elem = driver.find_element_by_id("user_password")
    elem.send_keys("password1")
    elem.send_keys(Keys.RETURN)
    elem.click()
    WebDriverWait(driver, 100).until(EC.url_changes(driver.current_url))
    element=WebDriverWait(driver, 10).until(EC.presenceOfElementLocated((By.XPATH,"//div[@class='sn-widget-list-title'][contains(.,'Dashboards')]"))).click()
   print(element)

When i execute it should login with user name and password , and then it will open another page, then I need to click on a link where it says dashboard.

Now what happens is it login sucessfully , then after going to main page, its throwing below error

    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
  (Session info: chrome=71.0.3578.98)

so I am not sure which element it was saying stale and its dashboard click is not working... can some one suggest what is wrong...so I used one chrome extension called truepath to know exact xpath for that Dashboard link...it said like

//div[@class='sn-widget-list-title'][contains(.,'Dashboards')]

When I another tool called Element locator, then I got xpath as below

//*[@id="b9169d55873212001ac119fa84e3ece3"]/div[1]/div[1]

When I do normal inspect on that dashboard link then do a copy of selector and xpath I get like this:

//*[@id="b9169d55873212001ac119fa84e3ece3"]/div/div

css selector:

#b9169d55873212001ac119fa84e3ece3 > div > div

This is html inspect for that dashboard

enter image description here

I tried all above for locating that element and then click but not working any suggestions please.

asp
  • 777
  • 3
  • 14
  • 33
  • Hi, i verified those two links for which my question was marked for duplicate, but that solution did not work :( – asp Feb 19 '19 at 08:28
  • one more thing i need to mention that dashboard link is within scroll bar..do I need to execute specific command to find dashboard link with in that scrollbar .. – asp Feb 19 '19 at 08:31
  • I would recommend to use full xpath, because of ID looks like its generated to avoid unexperienced web scrapers to scrap their website :) Hope it helps – StyleZ Feb 20 '19 at 13:14
  • @DebanjanB, I know that you are experienced, but still, you should atleast be helpful, when a person says that THIS IS NOT DUPLICATE, but you still mark it as one .... if you do, write him atleast a comment with a small explanation, it wont kill you // have a great day – StyleZ Feb 20 '19 at 13:16
  • @StyleZ I had no clue about the previous three comments as it seems I wasn't marked in any of those. Afterall 1) Title reading as `Selenium Python — this is not duplicate question..actually not able to locate element properly` neither seems to be a well researched question nor it fits our community standards . 2) OP haven't mentioned about his/her research. 3) As a canonical duplicate target was provided OP didn't turn up to edit the question to demonstrate how this question was different from the duplicate target. Hope that clears all the doubts. – undetected Selenium Feb 20 '19 at 13:26
  • 2
    Dear All, First thing to clarify since the mentioned suggested posts did not solve my probelm.. If you still some one feel that is duplicate, then i am sorry. I swear i made all attempts to solve the issue on my own, but struck at some point hence reaching out to experts here. No one perfect int his world, may be i did not post it correctly, but genuinely I have made attempts solve the problem on my own. So now glad to say I figured out the issue and solved my self. Thanks @StyleZ for your suggestions about full Xpath, that made way for my solution – asp Feb 25 '19 at 11:02

0 Answers0