Python Forum
How to click the button automatically using python
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to click the button automatically using python
#1
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.
Reply
#2
that URL gives me a
Error:
mdmdv.gartner.com’s server DNS address could not be found.
Recommended Tutorials:
Reply
#3
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
Reply
#4
(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.
Reply
#5
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
Reply
#6
(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?
Reply
#7
(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.
Reply
#8
Do you get any errors?
If you print(elem), what do you see?
Reply
#9
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
Reply
#10
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'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  cant click button by script at page michael1834 1 1,064 Dec-08-2023, 04:44 PM
Last Post: SpongeB0B
  Click on a button on web page using Selenium Pavel_47 7 4,710 Jan-05-2023, 04:20 AM
Last Post: ellapurnellrt
  Show HTML in Python application and handle click SamHobbs 2 2,732 Sep-28-2021, 06:27 PM
Last Post: SamHobbs
  button click error rafarangel 2 3,131 Feb-11-2021, 08:19 PM
Last Post: buran
  Log In Button Won't Click - Python Selenium Webdriver samlee916 2 3,834 Jun-07-2020, 04:42 PM
Last Post: samlee916
  How to click facebook message button JanelleGuthrie 2 2,414 May-14-2020, 06:02 PM
Last Post: Larz60+
  Contact form button click action Man_from_India 1 2,798 Feb-01-2020, 06:21 PM
Last Post: snippsat
  HOWTO? Login DSL Modem with Python Requests: need Click "Apply" Button Webtest 4 8,490 Aug-20-2019, 04:03 PM
Last Post: johnmina
  Selenium click on popup button??? GuJu 7 7,907 Jul-20-2019, 09:21 AM
Last Post: Nizam
  How to trigger click event on Button without ID/Name gahhon 7 14,005 Feb-10-2019, 03:06 PM
Last Post: gahhon

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020