0

I am using my RSelenium to iteratively collect data from web. Example structure of my code

`for (i in 1:100)
{
re$findElement(using='css', 'some id')$getElementText()
}`

But when an element is not found in the webpage, it throws an error called NoSuchElement.

I would like to know a code working like this.

for (i in 1:100) { re$findElement(using='css', 'some id')$getElementText() if NoSuchElement is found, break the loop and come out without stopping the program }

I tried using tryCatch, but I was unsuccessful.

Bharath
  • 1,600
  • 14
  • 25
  • When the console shoots you a "NoSuchElement", most of the time, you are incorrectly pointing to the element. More than likely there is something very small within your code confusing Selenium. Could we see actual script and possibly the element of the page you are trying to grab? – jagdpanzer Jan 11 '16 at 15:30
  • I am aware of that. Its like a table that updates each day in a webpage. Sometimes it does not update (during weekends). So when I search for an element one by one, last element may or may not be found. If an element is not present, I need to record the previous element as the final element of the table. – Bharath Jan 11 '16 at 15:31

1 Answers1

3

This answer!

solved the problem. Using while to check the NoSuchElement exception error.

Community
  • 1
  • 1
Bharath
  • 1,600
  • 14
  • 25