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, 2019 in Selenium by Srinivas
1,680 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

Not able to upload a file in Selenium Webdriver using python Scripting

Hey Srinivas, you can checkout this code ...READ MORE

answered Sep 10, 2019 in Selenium by Abha
• 28,140 points
3,930 views
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
• 58,090 points
23,456 views
+1 vote
2 answers

Is it possible to scroll down in a webpage using selenium webdriver programmed on python?

I using next code for facebook for ...READ MORE

answered May 16, 2019 in Selenium by mslavikas@gmail.com
25,583 views
+1 vote
1 answer
0 votes
2 answers

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,500 points
12,711 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,608 views
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,910 points
6,680 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,551 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP