0

Im trying to scrape some websites, but sometimes theres some that do not contain a button that the Code look for with findElement. So when the Code doesn't find what im looking for, it gives me the following error:

Selenium message:no such element: Unable to locate element: {"method":"link text","selector":"see more"}
  (Session info: chrome=104.0.5112.79)
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '4.0.0-alpha-2', revision: 'f148142cf8', time: '2019-07-01T21:30:10'
System info: host: '192.168.1.12', ip: 'fe80:0:0:0:4c4:faba:fe32:b5f4%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '12.5', java.version: '1.8.0_341'
Driver info: driver.version: unknown

I tried using findElements but after that its supposed to click the Element, so not possible with that function.

Any workaround?

6
  • You may use tryCatch or purrr::possibly Commented Aug 11, 2022 at 17:59
  • How you Call tryCatch with this seedesc= RemDr$findElement(using = "link text", value = "see more")$clickElement() ? @akrun Commented Aug 11, 2022 at 18:02
  • Not tested, perhaps you want tryCatch({RemDr$findElement(using = "link text", value = "see more")$clickElement()}, error = function(e) NA_character_) Commented Aug 11, 2022 at 18:05
  • keep happening same error @akrun. Code stops after error with selenium Commented Aug 11, 2022 at 19:08
  • 1
    Here is a similar case which may work for you Commented Aug 11, 2022 at 19:10

1 Answer 1

0

Use findElements() which can be accessed in list (list uses double brackets in R i.e. [[1]]) to click found elements:

seedesc <- RemDr$findElements(using = "link text", value = "see more")
seedesc[[1]]$clickElement()

#to click the second found element if there is one
seedesc[[2]]$clickElement() #etc...

When the element is not on the page, seedesc created by findElements() will be a list length 0:

element_exists <- isTRUE(length(seedesc)>0)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.