0

Hi I have been trying to automate a page using Selenium Python on MACOS. And in one of the page there is a file picker popup that is supposed be displayed to upload files. Manually when running I get to see the file picker popup but when running via script the file picker popup is not at all getting displayed.

Expected file picker popup The popup that is expected to be seen when the Upload Answers Button is click

On clicking the Upload Answer Button. The above popup is supposed to be displayed. enter image description here

Below is the script that is used.

from selenium.webdriver import Chrome
from random import shuffle
from time import sleep
from moviepy.editor import VideoFileClip
from selenium.common.exceptions import ElementClickInterceptedException
import math
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys

#To Enable the notification (Allow Microphone and Camera)
option = Options()

# option.add_argument("--enable-infobars")
# option.add_argument("start-maximized")
# option.add_argument("--enable-extensions")

# Pass the argument 1 to allow and 2 to block
option.add_experimental_option("prefs", {
    "profile.default_content_setting_values.media_stream_mic": 2,
    "profile.default_content_setting_values.media_stream_camera": 2,
    "profile.default_content_setting_values.geolocation": 1,
    "profile.default_content_setting_values.notifications": 1
})

driver = Chrome(options=option, executable_path='/Users/downloads/chromedriver')
driver.get('https://study.yupl.us/studies/5d5a64aa8b5bb92fb776753b')

#click Start Study
sleep(5)
try:
    element = driver.find_element_by_xpath("//button[text()='START STUDY']")
    driver.execute_script("arguments[0].click();", element)
except ElementClickInterceptedException:
    pass

#Enter the emailid
driver.find_element_by_name('email').send_keys('5d5a64aa8b5bb92fb776753b__relva@youplus.co')

#Enter the PASSWORD
password=driver.find_element_by_name('password')
password.send_keys('testtest')
password.send_keys(Keys.RETURN)

#click Start Study
sleep(5)
try:
    element = driver.find_element_by_xpath("//button[text()='START STUDY']")
    driver.execute_script("arguments[0].click();", element)
except ElementClickInterceptedException:
    pass


#Function to get the VIDEO DURATION
def GetVideoDuration(video_element):
    val = VideoFileClip(video_element)
    return val.duration

#Get The video duration and wait for the video to completly play
videoduration=0
try:
    sleep(10)
    questionvideo = driver.find_element_by_id('studyMediaVideo')
    video = driver.execute_script("return arguments[0].getAttribute('src')", questionvideo)
    videoduration = GetVideoDuration(video)
    # Play the video
    driver.execute_script("arguments[0].click();", questionvideo)
except ElementClickInterceptedException:
    pass


#wait till the video is fully played
sleep(math.ceil(videoduration))

#Click on Answer Question
try:
    answer=driver.find_element_by_xpath('//button[text()="ANSWER"]')
    driver.execute_script("arguments[0].click();", answer)
except ElementClickInterceptedException:
    pass

#Click on Upload Answer
try:
    sleep(3)
    upload_answer=driver.find_element_by_xpath('//button[text()="UPLOAD ANSWER"]')
    driver.execute_script("arguments[0].click();", upload_answer)
    print('clicked on upload answers button')
except ElementClickInterceptedException:
    pass

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.