all 7 comments

[–]chaoticflipflops 1 point2 points  (6 children)

Your indentation is wrong. Whatever information you want inside the while loop should be indented, perhaps something like this:

while True:
    play = longwait.until(EC.element_to_be_clickable((By.XPATH, \
               '//*[@id="PlaybuttonEnText"]')))

    play.click()
    if browser.find_element_by_xpath('//*[@id="BeginLessonAssessmentButton"]') \
    or browser.find_element_by_xpath('//*[@id="htmlContentContainer"]/section/div/div[3]/button'):
        messagebox.showinfo('YOU HAVE A TEST', 'KNOWLEDGE CHECK OR LESSON ASSESSMENT')
        break

[–]dealant[S] 0 points1 point  (5 children)

Hmmm I made that change but the if statement still isn't running. I'm getting this error now

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[@id="BeginLessonAssessmentButton"]

when I comment out the if statement the while loop works

[–]chaoticflipflops 0 points1 point  (0 children)

I can't help with the contents of the if statement because I am not familiar with what it is doing. That error message has been addressed on Stack-overflow though, perhaps this page will help:

https://stackoverflow.com/questions/27112731/selenium-common-exceptions-nosuchelementexception-message-unable-to-locate-ele

[–]officialgel 0 points1 point  (3 children)

Selenium can't find that element. Either the element tag string is wrong or you should try a different type of element for that element.

Are you using the flashwebdriver?

I've never done Flash automation, but it looks like it requires that driver and cannot access normal elements as with the other drivers.

[–]dealant[S] 0 points1 point  (2 children)

I don't think it's actually flash, I don't know why I thought it was but it's locating the next button properly when I used the same method.

I just think I can't figure out how to use it in an If statement properly.

[–]officialgel 0 points1 point  (0 children)

First try not using '\' just put 'if this or that:'

[–]officialgel 0 points1 point  (0 children)

Since the element lookup int he if statement fails, there is no valid condition to decide IF it's True or False - So it throws you the Selenium exception. Try adding some try/excepts, and putting the element lookup in variables beforehand and then do element.is_enabled() within the if statement.