473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

manipulating gui elements on a web page

13
I am a newbie to the python world. I am trying my hands at one task:

I am trying to access a website, say, "http://xyz.com" and then trying to maniulate the gui elememts already present on the page.

I am able to open the site using:

webbrowser.open("http://xyz.com")

But now, i have to enter some text in a text box and click on the button, which i am unaware how to do using python. Can anyone guide me through?

TIA,
rdps
Nov 8 '06 #1
15 6661
fuffens
38
Here is an example of how to use win32com to open the google page and paste python into the text field.

Expand|Select|Wrap|Line Numbers
  1. from win32com.client import *
  2. import time
  3. ie = Dispatch("InternetExplorer.Application")
  4. ie.Visible = 1
  5. ie.Navigate("www.google.com")
  6. time.sleep(1)
  7. page = ie.Document
  8. page.activeElement.value = 'python'
win32com is included in PythonWin (look at other posts from me). The sleep is a little lame. I am sure you can find a better way to check if the page is loaded.

Best regards
/Fredrik
Nov 8 '06 #2
rdps
13
Thanks a lot indeed!!!

Can one use cPAMIE module to do the same stuff ? i read about this this module in some of the other posting. Is looks simpler to use. Could there be some disadvantages of using the cPAMIE module? Please do let me know.
Nov 9 '06 #3
fuffens
38
I have never used cPAMIE, but from what I can read about it, it seems to be an easier way to control the web browser than to use COM. It is also a test framework. So if your intentions are to test a web solution you should defently try cPAMIE. And it's free! Thank you rdps. I will also take a look at cPAMIE when I have the time.

Best regards
/Fredrik
Nov 9 '06 #4
rdps
13
Hello,

cPAMIE definetly looks like an easier way but i am facing problems in extracting elements out of the tables, where in the tags in the html source view dont mention any id for the table identification.

All the functions related to the tables, ask for an id to be mentioned, which is unavailable to me. Do you see any solution?
Nov 9 '06 #5
rdps
13
I would elaborate my prev mail a bit. Say, i am havaing a html code for a web page:

<html>
<body>
<table>
<tr>
<td>"<a href="">abc"</a></td>
<td>"xyz"</td>
</tr>
<tr>
<td>"123"</td>
<td>"456"</td>
</tr>
</table>
</body>
</html>


now in all methods that PAMIE offers say, tableGetData (name) or tableExists (name) requires id, name or index as the parameter(name in this case).

Now for te above code what is the "name" which i should pass as parameter? How do i extract data from the table?

Regards,
rdps
Nov 9 '06 #6
fuffens
38
Hi rdps!

I am not that great at html, but from what I can see there is no id or name on your table. There probably has to be some sort of identification in order to access the table. When using COM you can request to get all links in a Document for example and then access them as a list with index in brackets, [i]. I am sure you can find all tables in a similar way. I haven't looked at the documentation of PAMIE, but maybe you can do the same thing using PAMIE.

BR
/Fredrik
Nov 9 '06 #7
fuffens
38
Here is how you would access a link with the previous COM example by retreiving a list of links

Expand|Select|Wrap|Line Numbers
  1. page.links[0].click()
I will look at PAMIE later... don't have time right now. Please let me know if you find a way!
Nov 9 '06 #8
rdps
13
I tried using com to achieve my goal i.e to manipulate various ui components on a web page.

I dont know why, but this seemingly correct code gives following error :
-------------------------------------------------- Code---------------------------------------------------------
<b>
Expand|Select|Wrap|Line Numbers
  1. import win32com.client 
  2.  
  3. ie = win32com.client.Dispatch("InternetExplorer.Application")
  4. ie.Visible = 1
  5. ie.navigate("http://google.com")
  6.  
  7. page = ie.Document
  8. links=page.links
  9. links[0].click()
</b>

----------------------------------------------------Error--------------------------------------------------------
Traceback (most recent call last):
File "C:\Eclipse\eclipse\workspace\p\src\pkg\try_with_c om.py", line 7, in ?
page = ie.Document
File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 491, in __getattr__
raise pythoncom.com_error, details
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147467259), None)
---------------------------------------------------END----------------------------------------------------------
I am able to topen the browser but nothin happens after that. Could you please guide me where ami going wrong?
Nov 10 '06 #9
bartonc
6,596 Expert 4TB
You need to wait for the app to get running:

Expand|Select|Wrap|Line Numbers
  1. import win32com.client
  2. from time import sleep
  3. ie = win32com.client.Dispatch("InternetExplorer.Application")
  4. ie.Visible = 1
  5. ie.navigate("http://google.com")
  6. sleep(10)
  7. page = ie.Document
  8. links=page.links
  9. links[0].click()
  10.  
works
Nov 10 '06 #10
rdps
13
Thnaks a ton!!! This did the trick.
Nov 10 '06 #11
bartonc
6,596 Expert 4TB
Thnaks a ton!!! This did the trick.
You are welcome! Of course, you can play with the length of the delay a bit. If you have a really fast internet connection , it may be more like 1 second. If you want it to run on slower internet connections, use something like this:
my internet connection is 3 Meg
lowest setting is 2 seconds
slowest internet connection to run is 56KBS
so
3/.056 = 53.57
53.57 times 2 seconds = 107 seconds for everybody to be able to run your program.
Nov 10 '06 #12
rdps
13
Hey! thanks for the explanation.

What i want to do next is enter text in the text box and click 'Saerch'. Any pointers regarding how to do that?

The real prb is where the gui elements have no ids associated in the respective html doc.
Nov 10 '06 #13
bartonc
6,596 Expert 4TB
Hey! thanks for the explanation.

What i want to do next is enter text in the text box and click 'Saerch'. Any pointers regarding how to do that?

The real prb is where the gui elements have no ids associated in the respective html doc.
There are two experts on this forum who very good with web stuff.
fuffens and kudos are really smart.

fuffens says


Expand|Select|Wrap|Line Numbers
  1. from win32com.client import *
import time
  • ie = Dispatch("InternetExplorer.Application")
  • ie.Visible = 1
  • ie.Navigate("www.google.com")
  • time.sleep(1)
  • page = ie.Document
  • page.activeElement.value = 'python'
  •  

  • Look at posts in this forum with similar names to query. If you click on the name of one of these experts, you can then "find all posts by ..." to see all the answers that they have given to others.
    Nov 10 '06 #14
    I am using PAMIE to access data from the internet. My question is how do I use PAMIE to obtain the functionality of the right mouse button? Essentially, I want to right click a link, then click on Save Target As...

    Any guidance will be appreciated.
    Dec 18 '06 #15
    bartonc
    6,596 Expert 4TB
    I am using PAMIE to access data from the internet. My question is how do I use PAMIE to obtain the functionality of the right mouse button? Essentially, I want to right click a link, then click on Save Target As...

    Any guidance will be appreciated.
    My guess is that PAMIE lets you run IE from behind the sceens and any action in IE's GUI from the user is handled by IE itself.
    Jan 3 '07 #16

    Sign in to post your reply or Sign up for a free account.

    Similar topics

    4
    by: Michael J. Astrauskas | last post by:
    Does anyone have a function for manipulating GET variables in a URL? I want to be able to modify some parameters without affecting others. An example of what I'm looking for: Let's say the...
    1
    by: john | last post by:
    All, I am writing a small application that allows users to create a new HTML file automatically, by entering just a few elements (page title, body text, etc). I can create the new page and...
    4
    by: Logico | last post by:
    Hi everybody, I need to do a function in javascript to check or uncheck all checkboxes with the same id. I want this function to work in every form and every page of my site, as I will use the same...
    2
    by: jingalls | last post by:
    I'm trying to modify a form so that when a user clicks a checkbox for a shorter version of the form, it will replace swap the default (long) form elements with the short version of elements, so...
    1
    by: Geir Sørensen | last post by:
    Hi, When I transform an xml-file using XslTransform, I seem to get a lot of elements of this form: <a> </a> <b> </b> But I really would like to get written out like I do when transforming...
    24
    by: RyanTaylor | last post by:
    I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
    4
    by: Greg Scharlemann | last post by:
    Hey all, I'm working on setting up a "Send this link to a Friend" page. The page has a couple of inputs and a textarea. I have some default text in the textarea that is populated at the time...
    2
    by: Dag Sunde | last post by:
    I have the following function to resize a div element (Content) depending on the size of another div element (leftConent). function adjustContentHeight() { var content =...
    3
    by: Ken Fine | last post by:
    I'm interested in programmatically manipulating groups of ASP.NET controls by type. Can someone suggest code for the following? Loop through, say, all label controls on a page, and assigning a...
    0
    by: DolphinDB | last post by:
    Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
    0
    by: ryjfgjl | last post by:
    ExcelToDatabase: batch import excel into database automatically...
    1
    isladogs
    by: isladogs | last post by:
    The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
    0
    by: Vimpel783 | last post by:
    Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
    0
    by: jfyes | last post by:
    As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
    0
    by: ArrayDB | last post by:
    The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
    1
    by: PapaRatzi | last post by:
    Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
    0
    by: Defcon1945 | last post by:
    I'm trying to learn Python using Pycharm but import shutil doesn't work
    0
    by: Shællîpôpï 09 | last post by:
    If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

    By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

    To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.