click certain button using mechanize - python

I'm trying to click a button with python and mechanize. The button looks like this:
<span>VOTE NOW!</span>
when going to the link manually, (www.example.com/#vote). It doesn't work. For some reason, it needs to click the button in the browser. I believe it runs a js script as when you click the button a small menu appears, with a form.
I've tried to look at what the form is, and what my script grabs from the main site, and don't find anything close to #vote.
I need to be able to click the button, to access the form, and submit data to the form, but can't find what to 'click'.

Related

How Can I automate clicking a button that only works when manually clicked?

I need to automate uploading a file to a website. I am using Selenium, and I am able to navigate through the site and select the file input I want from a drive on my computer. The only piece that does not work is clicking the Upload button.
driver = webdriver.Chrome(executable_path=r'P:/_Public/ScheduledTasks/SeleniumDriver/chromedriver.exe')
driver.get("https://client.schwabct.com?sId=MTUyMTM")
username = driver.find_element_by_name("userName")
username.clear()
username.send_keys(<userid>)
password = driver.find_element_by_name("password")
password.clear()
password.send_keys(<pw>)
driver.find_element_by_name("submitButton").click()
driver.get("https://client.schwabct.com/uploadData.action?currentApplication=87&currentRole=1&currentTab=16&currentModule=262&reset=Y")
driver.find_element_by_name("submitButton").click()
time.sleep(1)
upload_options = Select(driver.find_element_by_id("slctValue"))
upload_options.select_by_value("SECURITY_CHECKLIST")
fileinput = driver.find_element_by_id('uploadData_uploadDataInfo_fileUpload')
fileinput.send_keys(r"P:\_Public\Tamarac\Extracts\Upload_to_SCT\sct_upload_file.csv")
d = driver.find_element_by_id("isIgnoreHeaderId").click()
upload = driver.find_element_by_id("uploadButton").click()
I can run all the code just before the final button click, and it DOES upload the file if I then click the button manually. It gives an error when I try to automate the final button click. So the button is getting clicked, but the website does not recognize the file. The error text given by the website is "Cannot find file sct_upload_file.csv or file is empty."
I have tried switching to pyautogui right before the final button click to click on an image of the button. This also clicks the button, but it produces the same error as clicking the button with Selenium, even when using natural mouse movements through pyautogui to slowly move the mouse over the button and then click it.
HTML from the site
I have also tried using ActionChains to click the button. Again, I am able to click it, but I get the same error.
I have tried just selecting the element and using "upload.send_keys(Keys.RETURN)" on the subsequent line. It clicks the button, but I get the same error.
I have also tried moving the focus to the button, by sending TAB keys and by using switch_to, and then sending a RETURN key, but I have not been able to get the focus to actually move to the button.
When the final button is clicked the web page changes to a type of "wait while the file is uploaded" message.
Data is being processed screenshot
The page then changes again to display the error message.
Error message screenshot
The URL does not change. It is "https://client.schwabct.com/uploadData.action" for each page.
I figured out the answer myself. The code in the question was actually indented under a "with" statement that opened the csv file that was being uploaded. Moving the code out of the "with" statement, closing the csv file, allowed it to work without error.

Python/selenium How to interact with a fileUpload window without using Find_element?

I'm using selenium webdriver to automate some test for a page.
My page has three radio buttons. The third button when clicked pops up a file upload window.
So the user flow would be like this: Clicks on radiobutton, the window pops uo, the user select a file, then the file is uploaded and the radio button sets checked.
First I was doing this:
find_element(By.ID, 'file_uploader').sendKeys(filepath)
This worked well, except that the radio button never was clicked and so it wasn't checked after the upload.
Next I tried this:
find_element(By.ID, 'radio-button-id').click() #radio button is clicked and set checked
Now the fileUpload window raises and I want to write the path of the file in the file name field (the cursor is already there when the window appears)
I can't find the way to this last thing. I tried switch to the new window, sendKeys, actionChains.sendKeys, etc, nothing works.
I can not make a find_element of the file name field in the upload window.
Any suggestion? Thanks.
I also had some problems with file dialogs. No one of those approaches you suggested worked for me as well. Anyway, I realized that this kind of thing must be done outside of selenium. Reason: WebDriver does not manage dialogs, since they are domain of the operating system. The solution I've found so far is waiting for the user input.

How can I switch from one web page to other?

I want to create a webpage. In it there is a go_to button named goto_button. Whenever the user presses this button the new webpage will be called and the old one will be destroyed. To do this, I have to put a button on the web page, in the html file. However how can I switch from one web page to another? The go_to webpage address is www.kleol.com
if button is pressed
go to web-page kleol // how can I do that?
NOTE: I am new to Django.
Simple HTML tag like the following will work:
Go to Kleol
There's nothing that is django related.It is simple html.

how to trigger a button in HTML using python?

I want to trigger a button of a html file.
There is a web site in which there are number of options and a button.
After clicking on the button, using the options, a html table is created on next page.
I want to automate the process but I dont know how I can trigger a button using python.
DO anyone knows about the same?
You can use windmill, mechanize or selenium RC.

How to submit form on webpage in PYTHON?

I want to tick checkboxes, select radio buttons, write in text boxes and finally click on submit button to submit the form on a page. Programming in PYTHON only. How do i achieve this?
There are quite some solution. You can explore them and come back with a program, if it does not work.
Mechanize: http://wwwsearch.sourceforge.net/mechanize/
Python Auto Fill with Mechanize
Twill : - http://twill.idyll.org/
Python Paste: http://pythonpaste.org/
PAMIE: http://pamie.sourceforge.net/

Categories

Resources