I have the following Python code using Selenium to automate a button press:
from selenium import webdriver
import time
def main():
page_url = 'x.htm?'
driver = webdriver.Safari()
driver.get(page_url)
time.sleep(2)
elem = driver.find_element_by_xpath('yy')
elem.click()
driver.quit()
if __name__ == '__main__':
main()
I've removed the URL and button but they are valid. When I copy the code into an interactive Python console it runs and the click works; the browser is redirected. But when I run the code as as script, the click doesn't happen (the browser appears and the page renders but click is not registered).
Would love some help understanding why this is happening.