Using Selenium Webdriver Python Scripting file picker popup is not getting displayed and also unable to perform click on that element

0 votes

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 nn clicking the Upload Answer Button.

Following is the code that I tried or am using

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

In Actual when the Answer Button is click. File picker popup is supposed to be displayed. Instead no popup or error messages are shown.

I have also tried to upload the file using the below code on that button

METHOD #1

driver.find_element_by_xpath('//button[text()="UPLOAD ANSWER"]').send_keys(os.getcwd() + "/Users/Downloads/samsung_videos/video.mp4")


METHOD #2

driver.find_element_by_xpath('//button[text()="UPLOAD ANSWER"]').send_keys("/Users/Downloads/samsung_videos/video.mp4")

And Below is the HTML code for that element

<button class="ui button" role="button" style="background-color: rgb(31, 186, 238); color: white; border-radius: 0px; padding-left: 40px; padding-right: 40px; font-family: &quot;Open Sans&quot;; font-size: 17px; font-weight: 600; line-height: 20px; text-align: center; width: inherit; height: 50px; margin-top: 26px;">UPLOAD ANSWER</button>
Sep 10 in Selenium by Srinivas
134 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Selenium

0 votes
1 answer
0 votes
2 answers

Unable to Click on an Element in Selenium (Python) even after finding it.

Here, I give you working script which ...READ MORE

answered Sep 19, 2018 in Selenium by Priyaj
• 56,940 points
8,850 views
+1 vote
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,110 points
993 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,145 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
889 views