1

Good afternoon,

I am trying to open several links within a foreach using Facebook WebDriver, but it only opens the first one.

The links are arriving correctly, string, but on the second link it hangs and displays the error below.

It seems to me that selenium drive has a cookie or cache problem.

foreach($subjectsList as $subject)
{
    // Get all info subjects each course.
    $subjectTitle = $subject->getText();
    $subjectLink = trim($subject->getAttribute('href'));

    $rawPage = $this->seleniumDriver->get($subjectLink);
} // end Foreach for subjectsLis

enter image description here

Thanks in advance guys, any help is very welcome.

Alexis Philip
  • 517
  • 2
  • 5
  • 23
Gustavo Filgueiras
  • 353
  • 2
  • 3
  • 11

1 Answers1

1

It's not a cookie or a cache problem, it's conceptual.

$rawPage = $this->seleniumDriver->get($subjectLink); performs browser navigation. So, your code will correctly parse out the first link, and navigate to it. But, when it tries the second link, selenium correctly identifies that $subject is essentially a dangling pointer (well, it contains a C pointer which is technically the dangling pointer, but...) to a DOM element in the previous (deallocated) webpage/dom-tree.

To do what you're looking for, first parse out the titles/hrefs to strings, then iterate over the strings.

I'd take a look at the relevant documentation

Nate Symer
  • 2,185
  • 1
  • 20
  • 27
  • to de honest i can't undesterdant everything u told me. But, when u told me for to do title/href as a string, it's already did, when i tried to use .get(), i use string – Gustavo Filgueiras Jan 13 '20 at 22:46
  • 1
    The point is to extract all relevant info from `$subjectsList` before calling `get()`. Using the `get()` method causes the browser to load a new page from a url, replacing the currently loaded page (read the docs). Once that happens, the elements in `$subjectsList` are now part of a page that no longer exists. – Nate Symer Jan 15 '20 at 12:53
  • Thanks for reply me. I did what u told me, but still dosen't work :( It's not possible insert a new img here, so i did it on this link: https://share.getcloudapp.com/eDu9ry8z So i tried to do it a different way, now i got all the links in array then i iterate over it, but still not work when the line 735 it called. – Gustavo Filgueiras Jan 15 '20 at 18:04
  • i thinking i added u on my facebook, if not and ig u can help me, add me: facebook.com/gfilgueiras – Gustavo Filgueiras Jan 15 '20 at 18:09