Python Forum

Full Version: How to click the button automatically using python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Hi Experts,
I have one web page and it has one tab "upload file" . when manually press that button screen pops up and i select excel file and then we I press sumbit it automatically calls oracle function and perform some action.

I want to automate all this using till sumit using python. I have reached the point where I can open the web page and found the xpath of the "upload file" tab,but I am unable to understand how perform all remaining actions.
Also I am unable to upload screenshot so that I can show you all the steps which I follow manually.


Please help in resolving this issue.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

#Getting local session of Chrome
driver=webdriver.Chrome()

#put here the adress of your page
driver.get("http://mdmdv.gartner.com/mdm/app/marketingBounceBack")
#put here the content you have put in Notepad, ie the XPath
elem = driver.find_elements_by_xpath("//*[@id='emailTab']")
#elem2 = driver.find_elements_by_xpath("//*[@id='emailBounceBacks']/div/div[2]/label")
#("//*[@type='submit']")
#print(elem.get_attribute("class"))
#print(elem.get_attribute("value"))
elem.click()
driver.close()
When I run this web page open ups.
that URL gives me a
Error:
mdmdv.gartner.com’s server DNS address could not be found.
Hi Metulburr,

This url is internal to our project so you cannot access it ,so if you can share any generic example I will try to implement it in my code
(Nov-29-2017, 04:25 PM)purnima1 Wrote: [ -> ]This url is internal to our project so you cannot access it ,so if you can share any generic example I will try to implement it in my code
Its quite difficult help without seeing the html of the page your trying to manipulate. Your looking for an element using xpath. But its difficult to validate if your xpath with out looking at the webpage.

I also noticed, you have an ID for the tab your trying find. Why cant your just search for that element by an ID, rather than xpath. Because xpath could be quite tricky, it may return more than one elements which matched. If your guarantied to have unique ID's for each element in the page, best to use the id to lookup.

driver.find_element_by_id(...)
Alternatively - could you post the html where, the xpath your trying to match. That might be useful.
I need that too for a ASP.NET login with python. for a web crawler.
EDIT: i will post something here on forum to get help
(Nov-29-2017, 05:10 PM)p4t3x Wrote: [ -> ]I need that too for a ASP.NET login with python. for a web crawler.
EDIT: i will post something here on forum to get help

Do you have link to the page your trying to login?
(Nov-29-2017, 05:12 PM)hshivaraj Wrote: [ -> ]
(Nov-29-2017, 05:10 PM)p4t3x Wrote: [ -> ]I need that too for a ASP.NET login with python. for a web crawler.
EDIT: i will post something here on forum to get help

Do you have link to the page your trying to login?

Is a LAN page in ASP.NET i cant post it here, but i can post the code. i will open a thread. just wait a bit.
Do you get any errors?
If you print(elem), what do you see?
No I am not getting any error. The page opens up but as next step I want to click button "upload file" and open location from where I can choose file and then another button on same page "submit" to submit those files.

I want to share web page screenshot but I am not getting how to attach those
I have further modified my code but now I am getting error

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

#Getting local session of Chrome
driver=webdriver.Chrome()

#put here the adress of your page
driver.get("http://mdmdv.gartner.com/mdm/app/marketingBounceBack")
#put here the content you have put in Notepad, ie the XPath
#elem = driver.find_elements_by_xpath("//*[@id='emailTab']")
elem2 = driver.find_elements_by_xpath("//*[@id='emailBounceBacks']/div/div[2]/label").send_keys("C:\\Users\\pubhatia\\Documents\\project_related\\Jira_work\\month_wise_jira\\201712_release\\Data_enrichment_changes\\email_bounceback_template.xlsx")
elem2 = driver.find_elements_by_xpath("//*[@id='emailBounceBacks']/div/div[2]/label").click()
elem3=driver.find_elements_by_xpath("//*[@id='emailBounceBacks']/div/div[3]/button").click()
#("//*[@type='submit']")
#print(elem.get_attribute("class"))
#print(elem.get_attribute("value"))
#elem.click()
driver.close()
Error:
DevTools listening on ws://127.0.0.1:12689/devtools/browser/190121d5-9beb-4db5-98c1-b568cf879478 Traceback (most recent call last): File "openmdmtool.py", line 11, in <module> elem2 = driver.find_elements_by_xpath("//*[@id='emailBounceBacks']/div/div[2]/label").send_keys("C:\\Users\\pubhatia\\Documents\\project_related\\Jira_work\\month_wise_jira\\201712_release\\Data_enrichment_changes\\email_bounceback_template.xlsx") AttributeError: 'list' object has no attribute 'send_keys'
Pages: 1 2 3