How to find element Internet Explorer, using selenium and Python - python

I'm trying to enter text into a login page. The login page is:
https://ppair.uspto.gov/TruePassSample/AuthenticateUserLocalEPF.html
using "inspect elements" in Internet Explorer (the website only load in Internet Explorer) it seems to me that the name for the "select Digital certificate" text field is: "username"
This is my script:
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# Digital Certificate Path
DigitalCertificateFolder = 'C:\FOLDER'
DigitalCertificateFile = 'FILE.epf'
DigitalCertificatePath = DigitalCertificateFolder + '\\' + DigitalCertificateFile
password = 'PASSWORD'
# get the path of IEDriverServer
dir = 'C:\FOLDER2'
ie_driver_path = dir + "\IEDriverServer.exe"
# create a new Internet Explorer session
driver = webdriver.Ie(ie_driver_path)
driver.implicitly_wait(30)
driver.maximize_window()
# navigate to the application home page
driver.get("https://ppair.uspto.gov/TruePassSample/AuthenticateUserLocalEPF.html")
# get the search textbox
Select_Digital_Certificate = driver.find_element_by_name("username")
Select_Digital_Certificate.send_keys(DigitalCertificatePath)
This is the output from inspect element in Internet Explorer:
<INPUT name=username style="CURSOR: auto; BACKGROUND-IMAGE: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAASCAYAAABSO15qAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QsPDhss3LcOZQAAAU5JREFUOMvdkzFLA0EQhd/bO7iIYmklaCUopLAQA6KNaawt9BeIgnUwLHPJRchfEBR7CyGWgiDY2SlIQBT/gDaCoGDudiy8SLwkBiwz1c7y+GZ25i0wnFEqlSZFZKGdi8iiiOR7aU32QkR2c7ncPcljAARAkgckb8IwrGf1fg/oJ8lRAHkR2VDVmOQ8AKjqY1bMHgCGYXhFchnAg6omJGcBXEZRtNoXYK2dMsaMt1qtD9/3p40x5yS9tHICYF1Vn0mOxXH8Uq/Xb389wff9PQDbQRB0t/QNOiPZ1h4B2MoO0fxnYz8dOOcOVbWhqq8kJzzPa3RAXZIkawCenHMjJN/+GiIqlcoFgKKq3pEMAMwAuCa5VK1W3SAfbAIopum+cy5KzwXn3M5AI6XVYlVt1mq1U8/zTlS1CeC9j2+6o1wuz1lrVzpWXLDWTg3pz/0CQnd2Jos49xUAAAAASUVORK5CYII=); BACKGROUND-REPEAT: no-repeat; BACKGROUND-ATTACHMENT: scroll; BACKGROUND-POSITION: right center" type=text size=38 lpcachedvisval="1" lpcachedvistime="1491220212">
When I try to run the script in the console to receive the following error: "NameError: name 'Select_Digital_Certificate' is not defined".
Can someone please explain to me what I'm doing wrong?

Required input field located inside an iframe, so you need to switch to that iframe before handling input:
driver.get("https://ppair.uspto.gov/TruePassSample/AuthenticateUserLocalEPF.html")
driver.switch_to.frame('entrustTruePassGuiFrame')
Select_Digital_Certificate = driver.find_element_by_name("username")
...
To switch back to main HTML document you might need to use
driver.switch_to.default_content()

Related

Unable to upload file using selenium with python: ElementNotInteractableException. Element is not reachable by keyboard

I have read all the available answers on stackoverflow related to my query but no answers is solution of my problem. I am trying to upload a document from desktop using python script but script gets failed in between with Exception. Scripts throws Exception in following python code
frame1 = driver.find_element_by_id("BrowseButton")
driver.switch_to.frame(frame1)
document_to_attach = wait.until(EC.element_to_be_clickable((By.XPATH, "//object[#class='swfupload']")))
document_to_attach.send_keys(r"C:\Users\Desktop\sample.msg")
Exception is
selenium.common.exceptions.ElementNotInteractableException: Message: Element <object id="SWFUpload_0" class="swfupload" type="application/x-shockwave-flash"> is not reachable by keyboard
HTML Code corresponding to this element is
<iframe style="position: relative; top: 5px;" border="0" src="DocumentUploadForm.jsp?DocID=21UZZZQ5UGKEZN5OBTZQ51JZR1BJD3ZZ&maxNumFiles=3&Time=1584360999619"" name="BrowseButton" id="BrowseButton" scrolling="no" width="100" height="32" frameborder="0">
</iframe>
<object id="SWFUpload_0" type="application/x-shockwave-flash" data="swfupload/swfupload.swf" class="swfupload" style="" width="20" height="20">
<param name="wmode" value="transparent">
<param name="movie" value="swfupload/swfupload.swf">
<param name="quality" value="high">
<param name="menu" value="false">
<param name="allowScriptAccess" value="always">
<param name="flashvars" value="movieName=SWFUpload_0&uploadURL=%2Fhome%2Fgold%2Fjsp%2FDocumentUploadReceiver.jsp%3FTWCSESSIONID%3Drmgw946kr5mi46v8srwuewbs&useQueryString=false&requeueOnError=false&httpSuccess=&assumeSuccessTimeout=0&params=&filePostName=Filedata&fileTypes=*.*&fileTypesDescription=All%20Files&fileSizeLimit=64%20MB&fileUploadLimit=3&fileQueueLimit=3&debugEnabled=false&buttonImageURL=%2Fhome%2Fgold%2Fjsp%2F&buttonWidth=20&buttonHeight=20&buttonText=&buttonTextTopPadding=0&buttonTextLeftPadding=0&buttonTextStyle=color%3A%20%23000000%3B%20font-size%3A%2016pt%3B&buttonAction=-110&buttonDisabled=false&buttonCursor=-2"></object>
This is the image
Manually if I open website and uploading the document, it is successfully browsing document from desktop and uploading it. When I am using selenium script with Firefox Web Browser , it is giving the above exception. While running automation script, if manually I am trying to click this element than also I am unable to click it and it appears as an image on browser.
I think it may be related to Flash object or some plugins or something else.
What is the reason behind this exception and how to solve this exception
Use presence_of_element_located. The element you are sending text to may not be clickable.
If that does not work try the commented out like that contains WebDriverWait(driver, 10)
from selenium.webdriver.support.ui import WebDriverWait
frame1 = driver.find_element_by_id("BrowseButton")
driver.switch_to.frame(frame1)
document_to_attach = wait.until(EC.presence_of_element_located((By.XPATH, "//object[#class='swfupload']")))
#document_to_attach = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//object[#class='swfupload']")))
document_to_attach.send_keys(r"C:\Users\Desktop\sample.msg")
The reason behind the exception is due to flash used by website.So added the following line of code-
firefoxProfile = webdriver.FirefoxProfile()
firefoxProfile.set_preference("plugin.state.flash", 2)
driver = webdriver.Firefox(firefoxProfile, executable_path=r'drivers\geckodriver.exe')
Also after it, automation script was not giving path using send_keys and hence found solution to use pyautogui library or autoit library. Following code is used for this purpose-
frame1 = driver.find_element_by_id("BrowseButton")
driver.switch_to.frame(frame1)
document_to_attach = wait.until(EC.element_to_be_clickable((By.XPATH, "//object[#class='swfupload']")))
document_to_attach.click()
import time
time.sleep(5)
import autoit
autoit.control_focus("Open", "")
autoit.control_set_text("Open", "Edit1", r"C:\Users\Desktop\sample.msg")
autoit.control_click("Open", "Button1")
You have to install autoit module in case if you do not have it by pip install autoit

Selenium with Python: collecting an email from a form with read only

I am trying to collect email addresses from a form on a website that has readonly inside of it.
<input name="email" id="email" type="text" class="form-control" value="example#gmail.com" readonly="">
I want to be able to get the email address (example#gmail.com) but everything I try returns "unable to locate element".
Everything is configured properly as the rest of the script is working fine, which I have left out.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import re
import pandas as pd
import os
x = 0
all_volunteers = driver.find_elements_by_xpath('//*[#title="View volunteer record"]')
for volunteer in all_volunteers:
volunteer.click()
driver.implicitly_wait(3)
# email_add = driver.find_element_by_id('emaillabel')
#email_add = driver.switch_to_frame(driver.find_element_by_name('email'))
#print(email_add.get_attribute('email'))
#email_add = driver.find_element_by_css_selector('input id')
#email_add = driver.find_element_by_xpath('//input [#name="email"]')
#email_add = driver.find_element_by_tag_name('Email Address')
email_add = driver.find_element_by_xpath('//*[#id="email"]')
print(email_add.get_attribute('value'))
# back button
driver.execute_script("window.history.go(-1)")
#increase counter by 1
x += 1
Everything commented out (followed by #) is what I have tried.
Is any one able to tell me what I am doing wrong or missing?
I have a debugging solution to locate the element.
In the browser, open the web page containing the email input
Open developer tools (F12)
Open console tab in the developer tools
Type $x('//input[#id="email"]') and see if the element is located. This is the native xpath locator
You can also try document.getElementById('email') in the console
If the element is not found still, try the iFrame selector marked in the screenshot to identify iframes and switch to it.
If more than one element is returned, it means that you might have to modify the selector to find unique element.

Selenium input text that has dropdown & hidden values

I am writing a python script to input text, that then has a dropdown appear to select from a list of items. These items are all hidden values and are not inputted to the webpage until selected by clicking on said item.
Specifically I am attempting to input data on Fitbits website to track food (a thing for work, but it is tedious to input food consumption each day). I would like to automate this :)
My script currently looks like this...
#! python3
# fitbitSubmitFood.py this script submits the food log on fitbit.com
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
browser = webdriver.Chrome()
# open webpage to log food
browser.get('https://www.fitbit.com/foods/log')
# login to the website
# email username input
emailSelect = browser.find_element_by_xpath('//*[#id="loginForm"]/fieldset/dl/dd[1]/input')
emailSelect.send_keys('EMAIL')
# email password input
inputPassword = browser.find_element_by_xpath('//*[#id="loginForm"]/fieldset/dl/dd[2]/input')
inputPassword.send_keys('PASSWORD')
# click log in
clickLogin = browser.find_element_by_xpath('//*[#id="loginForm"]/div[1]/button')
clickLogin.click() # clicky click!
# input What did you eat?
foodSelect = browser.find_element_by_xpath('//*[#id="foodselectinput"]')
foodSelect.send_keys('Pizza, Bread') # select by visible text
# input How Much?
howMuch = browser.find_element_by_xpath('//*[#id="quantityselectinput"]')
howMuch.send_keys('3')
# click Log Food
logfood = browser.find_element_by_xpath('//*[#id="foodAutoCompButton"]')
# logfood.click() # clicky click!
# Close web browser
The current script above throws the following error.
selenium.common.exceptions.InvalidElementStateException: Message: invalid element state
So I have also tried suggestions from this stackoverflow question.
Entering a value into a type="hidden" field using Selenium + Python
WebDriverWait(foodSelect, 10).until(EC.visibility_of_element_located((By.XPATH,'//*[#id="foodId"]'))) # wait for hidden text to populate
This threw the following error...
selenium.common.exceptions.TimeoutException: Message:
Here is a snippet from the website
input type="text" name="foodselectinput" id="foodselectinput" class="text columnFull yui-ac-input" maxlength="80" tabindex="1" autocomplete="off"
I can see the following on the website for the hidden value. This value is not passed to the webpage until after the food is selected from the drop down menu.
input name="foodId" id="foodId" type="hidden" value="13272"
Note: I have already tried using the click method for the Pizza, Bread
clickFood = browser.find_element_by_xpath('//*[#id="foodselectcontainer"]/div/div[2]/ul/li[1]/div/div[1]')
clickFood.click() # click it!
This did not work.
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#id="foodselectcontainer"]/div/div[2]/ul/li[1]/div/div[1]"}
The script cannot continue until the food item is selected on the webpage. Hence, the question.
How would one pass the hidden value or select from a dropdown?
From your snippet
input type="text" name="foodselectinput" id="foodselectinput" class="text columnFull yui-ac-input" maxlength="80" tabindex="1" autocomplete="off"
yui-ac-input refers AutoComplete from YUI 2 Library (That's what I thought)
As the site mentioned by you asked credentials. I created a sample code for YUI Example
Sorry I dont know python.Below is a Java code. The syntax looks more or less same. So get the idea from below code and implement it
public void start() {
driver.get("http://yui.github.io/yui2/docs/yui_2.9.0_full/examples/autocomplete/ac_basic_array.html");
yuiAutoSuggestSelect("Cali");
}
public void yuiAutoSuggestSelect(String value) {
WebElement inputElement = driver.findElement(By.className("yui-ac-input"));
inputElement.sendKeys(value);
By autoSuggSel = By.xpath("//div[#class='yui-ac-container']//div[#class='yui-ac-bd']//li");
WebElement autoSuggestEl = driver.findElement(autoSuggSel);
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOf(autoSuggestEl)).click();
}

Can't Click an Object in Selenium in Some Google Image Search Results

I'm trying to pull urls of images from Google Image Search results. As you know from using Google Image Search you click on a small photo in the grid to get a bigger image to pop down below it. This is where my Selenium Chrome Webdriver stops.
I've tried the .click() command and the .send_keys(Keys.RETURN) command. I've also tried the .send_keys(Keys.CONTROL + Keys.RETURN) command to try to open it in a new tab.
There are four different elements under the search result of the small image I want to click on in order to get at the full image. Three of the elements return a
"selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element"
The X-Path in the code below doesn't give that error but it doesn't do anything. Terminal just goes back to the $ prompt.
I can't seem to get the photo and buttons below to pop down for anything. When I tell Selenium to do things to elements in the menu I can't get to open it says the element is not visible.
I don't want to use their API because I need more images than their API limits.
Here's the code. I'm thinking of another option below this code.
import requests
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
list3 = ["rags and scraps"]
#Setup The Automated Browser (brew install chromedriver)
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=/user/anthonycelio/selgoog/chrome_driver') #Path to your chrome profile
driver = webdriver.Chrome('/usr/local/Cellar/chromedriver/2.27/bin/chromedriver')#, chrome_options=options) #Type 'brew list chromedriver' to find path
driver.get("https://www.google.com/search?q=cats+and+dogs&safe=off&espv=2&biw=1599&bih=726&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiI56_7isXSAhXC4iYKHcbZCLEQ_AUIBigB#q=cats+and+dogs&safe=off&tbm=isch&tbs=sur:fc&*")
for i in list3:
driver.find_element_by_xpath("""//*[#id="lst-ib"]""").clear()
inputElement = driver.find_element_by_xpath("""//*[#id="lst-ib"]""")
inputElement.send_keys(list3)
driver.find_element_by_xpath("""//*[#id="_fZl"]""").send_keys(Keys.RETURN)
driver.find_element_by_xpath("""//*[#id="rg_s"]/div[1]/a""").click()
This might be a different option to store the url of the image if Google has made their images unclickable by Selenium: One of the elements has the link in it if you copy the outerHTML. The problem is they have stuffed code into the link. I wonder if it can be removed with any consistency.
<img class="rg_ic rg_i" data-sz="f" name="ziffAZE9s2oycM:" alt="Image result for rags and scraps" jsaction="load:str.tbn" onload="google.aft&&google.aft(this)" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxQTEhUUExQWFhUVFxcYFxcYGBwcHRgWHBQYFxcYGhcYHSggGBolHBUXITEhJSkrLi4uFx8zODMsNygtLisBCgoKDg0OFA8PFywcFBwsLCwsLCwsLCwsLCssLCwsLCwrLCwsLCwsLCwsLCw3NywsLCwsLDcsLCssKzcsNyw3K//AABEIAMUBAAMBIgACEQEDEQH/xAAbAAABBQEBAAAAAAAAAAAAAAACAQMEBQYAB//EAEEQAAEDAgMEBggDBwMFAQAAAAEAAhEDIQQSMQVBUWEGEyJxgZEVMlKhscHR8CNC4RQzQ2KCkvEHcsIWU6Ky0iX/xAAYAQEBAQEBAAAAAAAAAAAAAAAAAQIDBP/EABsRAQEBAQEBAQEAAAAAAAAAAAABETESAiFB/9oADAMBAAIRAxEAPwC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VJ1K5crkNf/Z" style="width: 209px; height: 161px; margin-left: -10px; margin-right: -11px; margin-top: 0px;"><div class="_aOd rg_ilm"><div class="rg_ilmbg"><span class="rg_ilmn"> 7290 × 5614 - commons.wikimedia.org </span></div></div>
https://upload.wikimedia.org/wikipedia/commons/a/ab/Frank_G._Carpenter,_Salvaging_scraps_on_the_streets_of_Paris.jpg
The easiest option would be the second thing you mentioned. You can extract the href value, then run it through urllib's unquote function. When you are on the image results page:
import urllib
images = driver.find_elements_by_class_name('rg_l')
for image in images:
href = image.get_attribute('href')
if '?imgurl=' in href: # Do this because often times the last result will not be an actual image
image_url_raw = href.split('?imgurl=')[1].split('&imgrefurl=')[0]
image_url = urllib.unquote(urllib.unquote(image_url_raw))
If you are on Python3, you need to use urllib.parse.unquote(urllib.parse.unquote(image_url_raw)) instead

Interacting with website forms

I'm trying to connect to a school url and automate the process with selenium. Originally I tried using splinter, but ran into similar problems. I can't seem to be able to interact with the username and password fields. I realized a little ways in that it is an iframe that I need to interact with. Currently I have:
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("https://my.oregonstate.edu/webapps/login/")
driver.switch_to.frame('Content') #I tried contentFrame and content as well
loginid = driver.find_elements_by_id('user_id')
loginid.send_keys("***")
passwd = driver.find_elements_by_id('password')
passwd.send_keys("***")
sub = driver.find_elements_by_id('login')
sub.click()
time.sleep(5)
driver.close()
Here is the HTML that I am trying to interact with:
The Website: https://my.oregonstate.edu/webapps/portal/frameset.jsp
The iframe:
<iframe id="contentFrame" style="height: 593px;" name="content" title="Content" src="/webapps/portal/execute/tabs/tabAction?tab_tab_group_id=_1_1" frameborder="0"></iframe>
The forms:
Username:
<input name="user_id" id="user_id" size="25" maxlength="50" type="text">
Password:
<input size="25" name="password" id="password" autocomplete="off" type="password">
It seems that selenium can locate the elements just find, but I am unable to input any information into these fields, I got the error 'List object has no attribute'. When I realized it was the iframe I tried to navigate into that but it says 'Unable to locate frame: Content'. Is there another iframe that I am missing? Or something obvious? This is my first time here so sorry if I messed something up with the code linking.
Thanks for the help.
driver.switch_to.frame() takes frame's id or name, where your frame have id = contentFrame and name = content. (The reason they didn't work is probably because of a different issue, read through please)
First, please try use either one of them, not Content (which has upper case C).
Once you have fixed the issue above, there will be another error in your code.
loginid = driver.find_elements_by_id('user_id')
loginid.send_keys("***")
driver.find_elements_by_id finds all matching elements, which is a list. So you can't use send_keys. Please use driver.find_element_by_id('user_id').
Here is the code I tested working.
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://my.oregonstate.edu/webapps/login/")
driver.switch_to.frame('content') # all lower case to match your actual frame name
loginid = driver.find_element_by_id('user_id')
loginid.send_keys("***")
passwd = driver.find_element_by_id('password')
passwd.send_keys("***")
Regarding issue in your following comments
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://my.oregonstate.edu/webapps/login/?action=relogin")
loginid = driver.find_element_by_id('user_id')
loginid.send_keys("***")
passwd = driver.find_element_by_id('password')
passwd.send_keys("***")
driver.find_element_by_css_selector('.submit.button-1').click()

Categories