Troglodyne-Internet-Widgets / selenium-client-perl

WC3 Selenium client for Perl
6 stars 4 forks source link

Close Session Forced #9

Closed tiroso closed 3 years ago

tiroso commented 3 years ago

Hello again in this repo, Everytime I try to find an element, which is not there, my session will automatically closed. I cant find the parameter for just warning and not destroying my session.

teodesian commented 3 years ago

That sounds pretty bad. Is a die() being thrown, or is it warning and whacking the session somehow?

tiroso commented 3 years ago

Here is the die message

SubProcess: onRun returned error: Not Found :
 Consult https://www.w3.org/TR/webdriver1/#dfn-find-element
Raw Error:
{"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"css selector\",\"selector\":\"#onetrust-accept-btn-handler\"}\n  (Session info: chrome=91.0.4472.114)","stacktrace":"#0 0x55913f09a949 \u003Cunknown>\n"}}
 at /usr/local/share/perl/5.28.1/Selenium/Client.pm line 304.
        Selenium::Client::_request(Selenium::Client=HASH(0x5605510dfcf8), "FindElement", "sessionid", "7e7071f5485c52450cfe131f0c69b356", "value", "#onetrust-accept-btn-handler", "using", "css selector", ...) called at /usr/local/share/perl/5.28.1/Selenium/Subclass.pm line 53
        Selenium::Subclass::_request(Selenium::Session=HASH(0x560552054020), "FindElement", "using", "css selector", "value", "#onetrust-accept-btn-handler") called at /usr/local/share/perl/5.28.1/Selenium/Subclass.pm line 75
        Selenium::Subclass::__ANON__(Selenium::Session=HASH(0x560552054020), "using", "css selector", "value", "#onetrust-accept-btn-handler") called at ./FHEM/98_SeleniumContainer.pm line 149
        main::SeleniumSpotifyContainer_onRun(SubProcess=HASH(0x5605524a3498)) called at FHEM/SubProcess.pm line 317
        eval {...} called at FHEM/SubProcess.pm line 317
        SubProcess::run(SubProcess=HASH(0x5605524a3498)) called at ./FHEM/98_SeleniumContainer.pm line 363
        main::SeleniumSpotifyContainer_DoInit(HASH(0x560550da4630)) called at ./FHEM/98_SeleniumSpotifyContainer.pm line 469
        main::SeleniumSpotifyContainer_Read(HASH(0x560550da4630)) called at fhem.pl line 3806
        main::CallFn("c00", "ReadFn", HASH(0x560550da4630)) called at fhem.pl line 762

There is no error message if the button is located on the site... I can handle it with eval{} but i think thats not an elegant solution.

Working:

eval{
   $session->FindElement( using => 'css selector', value => '#onetrust-accept-btn-handler' )->ElementClick();
};

Not working (throws error and process died) (but is working when the Element is found:

if (my $element = $session->FindElement( using => 'css selector', value => '#onetrust-accept-btn-handler' )){
   Log3 undef, 1, "Found Accept Button";
}else{
   Log3 undef, 1, "Didn't Found Accept Button";
}
tiroso commented 3 years ago

In your other repo i have to call the function "find_element_by_css" to throw just a warning and not to kill and destroy the session. Maybe i've just not read the hint for Selenium::Client

teodesian commented 3 years ago

Ahh. So it's just dying. Some people like the sort of "klingon programming" paradigm (better to die() than return() in failure), so I think I should make this behavior controllable via a switch passed on instantiation.

I'll implement this feature later this week.