0

I am trying to click on the "Next" button of a webpage, but I'm receiving an error. The steps I took to reach the table:

  1. Go to ibl.mdanderson.org/fasmic/#!
  2. Type and select AKT1 (3 mutations) (NOTE:'GO' button doesn't work, please click the option from the drop-down)
  3. Click on the green button with the text 'MS', a new table will appear.
  4. In this new table, there will be a tab called literature.
  5. At the end of the literature tab, there will be a "Next" button to go to the next page.

I need to parse data from the literature tab(which works perfectly). However, I cant go to the next page to parse data from the same table.

Following is the code:

driver.find_element_by_xpath("//*[contains(text(),'Literature')]").click()
        for elements in driver.find_elements_by_css_selector("#literature_div [ng-repeat]"):
            print(elements.text,"\n")
            driver.implicitly_wait(5)
driver.find_element_by_xpath('//a[@ng-click="selectPage(page + 1, $event)"]').click()

After executing this, I get the following error:

"Message: The element reference of is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed"

RRg
  • 123
  • 1
  • 12
  • I see those items are getting logged in the console. [Here's a thread](https://stackoverflow.com/questions/20907180/getting-console-log-output-from-chrome-with-selenium-python-api-bindings) where someone captures the log. Probably easier than troubleshooting that message. – pguardiario Nov 15 '18 at 22:55

2 Answers2

0

At the end of literature tab try

driver.find_element_by_xpath('/html/body/div/div[2]/div[2]/div[1]/div/div/div[3]/div/div/div[5]/div/ul/li[7]/a').click()
  • I still get the same error: Message: The element reference of
    is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
    – RRg Nov 15 '18 at 16:10
0

Have you tried

driver.find_element_by_css_selector('[ng-click="selectPage(page + 1, $event)"]').click()

You can improve but this works for the click (Assuming I am targeting the right Next)

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

url = "https://ibl.mdanderson.org/fasmic/#!/"
d = webdriver.Chrome()
wait = WebDriverWait(d, 10)
d.get(url)
d.find_element_by_css_selector('[type=text]').send_keys('AKT1 (3 mutations)')
d.find_element_by_css_selector("input[type='text']").send_keys(Keys.RETURN)
btn = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".btn.btn-default.btn-tab-avail")))
btn.click()
d.find_element_by_css_selector("[heading=Literature]").click()

ele = wait.until(EC.text_to_be_present_in_element((By.CSS_SELECTOR, "#literature_div [ng-repeat]"), "PMID"))
eles = d.find_elements_by_css_selector("#literature_div [ng-repeat]")

d.find_element_by_css_selector('[ng-click="selectPage(page + 1, $event)"]').click()

#d.quit()
QHarr
  • 83,427
  • 12
  • 54
  • 101