0

I'm just trying to figure out how to check if the title of a specific page has loaded in selenium using python, and if it hasn't then go back to the beginning (continue)

However, it's not working at all, when I get a 500 error, or the page does not load at all. Why is this not working as it should? Is there a different way to do this?

try:
    element = WebDriverWait(self.driver, 2).until(
        EC.title_is("This is my title")
    )
except TimeoutException as ex:
    print(ex.message)
    self.driver.quit()
    continue
Andersson
  • 51,635
  • 17
  • 77
  • 129
Ke.
  • 2,484
  • 8
  • 40
  • 78
  • That really doesn't seem to be close to enough information. There's no error message and noone knows the site except you. A 500 error is internal server error, which means their server isn't working and you can't use selenium effectively on a site that doesn't work – codyc4321 Mar 13 '17 at 15:40
  • So is there a way to detect this error? Can I use unittest for instance? – Ke. Mar 13 '17 at 15:41
  • @Ke. could it be "not working" because you quit the driver in the exception handler? Could you show the rest of the code? Thanks. – alecxe Mar 13 '17 at 15:46
  • if the page loads when you go to normal browser than there's an issue in your code, not their site – codyc4321 Mar 13 '17 at 15:54
  • @alecxe the thing is if that were the case, I would get a printed message before from the "ex.message" print statement. However, I'm only getting an error from selenium. I can put a print statement before the driver.quit and that doesnt get printed either, so it looks like something wrong with the try statement,. – Ke. Mar 13 '17 at 15:57
  • 2
    @Ke. not sure if it is helpful, but here is a small sample that works for me - getting 2 `HERE!` messages printed on the console: https://gist.github.com/alecxe/33ee76a612f8996199d947d5ce996309. – alecxe Mar 13 '17 at 15:58
  • @codyc4321 I'm using a proxy, so could it be that I can error check here? I'm pretty sure the reason it's 500 error is becuase of the proxy, but how can I error check this? – Ke. Mar 13 '17 at 15:59
  • if it isn't a TimeoutException it won't do anything. I never use try except that specific until I know exactly what error occur – codyc4321 Mar 13 '17 at 16:03
  • with a full code sample we can run I'm sure alex or I could fix it quickly but I won't troubleshoot something that's impossible to troubleshoot. try using a normal try/except for now – codyc4321 Mar 13 '17 at 16:04
  • Hi @alexce, thanks so much for this code example, I realise now that it is a problem with the firefox driver. Not too worried about this as I can use chrome for now, but its real difficult to get the script doing the same thing with all these different drivers (for instance, when I want to go headless using phantomjs I have to do a bunch of extra scripting to get it to work) If you can write the answer I will accept it because its correct. – Ke. Mar 13 '17 at 16:15

0 Answers0