Ringo_00
Ringo_00

Reputation: 57

Copy text from website using Selenium for python

I'm trying to copy text from a website with the following code and I want it to automatically click the "NEXT" button at the end of the table, without clicking it the code works just fine but when I add the last line to click it gives the error:

"Message: Element is no longer attached to the DOM Stacktrace: at fxdriver.cache.getElementAt (resource://fxdriver/modules/web-element-cache.js:9354) at Utils.getElementAt (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/[email protected]/components/command-processor.js:8978) at WebElement.getElementText (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/[email protected]/components/command-processor.js:11965) at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/[email protected]/components/command-processor.js:12534) at DelayedCommand.prototype.executeInternal_ (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/[email protected]/components/command-processor.js:12539) at DelayedCommand.prototype.execute/< (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/[email protected]/components/command-processor.js:12481)"

The code I'm using is:

driver = webdriver.Firefox()
driver.get("https://it.website.com/Statistics")
wait = ui.WebDriverWait(driver, 10)
wait.until(page_is_loaded)
Next_first = 0
Next_first = driver.find_elements_by_id("next")[0]
data_vector [i]=driver.find_elements_by_class_name("tn")[i].text
Next_first.click()

While the website code is:

<tr>
  <td class="tn"> text
  </td>
  <table class="table class" id="table id">
    <thead>...code for table title...
    </thead>
    <tbody>
      <tr>
        <td class="tn">data
        </td>
      </tr>
    </tbody>
    <dd>
      <a class="option clickable" id="next" data-page="1">NEXT</a>
    </dd>
</tr>

Upvotes: 0

Views: 1562

Answers (1)

user5923627
user5923627

Reputation:

Is there more than the html-source, like javascript? Because the input could be detached by javascript, which means you have to wait for it to load properly ( driver.implicitly_wait(#seconds) )

here the link to the discription of "implicit-waits"

The second solution could be that you have to clear the cache/cookies of the webdriver before testing, which is described here

Upvotes: 0

Related Questions