in reply to The Document Inspector, finding elements in page (Re^3: WWW::Mechanize::Firefox -- how to close firefox browser window)
in thread WWW::Mechanize::Firefox -- how to close firefox browser window
Thanks again, Corion. For those interested, here's what worked for me. I included in my code sections for downloading a text file and closing windows which were subjects of the thread.
If anyone has any advice on how to make this script run faster, I'd love to know how, but I'm just glad it works.
(1) Install Firefox DOM Inspector add-on and open the DOM Inspector from Tools -> Web Developer -> DOM Inspector.
(2) In the DOM Inspector, load the webpage from File -> Inspect Content Document.
(3) Click "Inspect" at the top right to view the webpage, and select "Document-DOM Nodes" on the left and "Object-DOM Node" on the right, and click "Find a node to inspect by clicking on it" at the top left.
(4) Click on the actual scrollbar to hightlight the whole listbox on the webpage (clicking the elements in the listbox didn't give useful information).
(5) The information generated tells me that the listbox has the name 'speciesList', it's within the form 'frmManager', and the selection I want, "Saccharomyces cerevisiae(25)", has value '0'. I use this information with simple WWW::Mechanize::Firefox commands in my Perl script, as below.
#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize::Firefox; use Firefox::Application; use WWW::Scripter; my $ff = Firefox::Application->new(); my $mech = WWW::Mechanize::Firefox->new(autoclose => 1); $mech->get("http://david.abcc.ncifcrf.gov/summary.jsp"); $mech->click({ xpath => ('//*[@href="Upload a Gene List or Population" +]', single => 1), synchronize => 0 }); $mech->form_name('frmManager'); $mech->set_fields( 'pasteBox' => "RRI1, YLR149C, FUN19, YBR285W, ALD3, CUE5, RTC3 +, AIM3, YDL199C, FMP45, AST2, GIP2, YKL091C, YKL133C, GLG2, SYM1, VHS3, YJR124C, MCH1, MHO1, I +KS1, RKM1, STF2, SAC1, ATG7, YAK1", 'Identifier' => "OFFICIAL_GENE_SYMBOL", ); $mech->click ({ xpath => ('//input[@name="rbUploadType" and @value="li +st"]', single => 1), synchronize => 0 }); $mech->click({xpath => ('//*[@value="Submit List"]', single => 1), syn +chronize => 0}); $mech->back; $mech->form_name('frmManager'); $mech->set_fields( 'speciesList' => 0); $mech->click({xpath => ('//*[@value="Select Species"]', single => 1), +synchronize => 0}); $mech->back; $mech->click({xpath => ('//*[@value="Functional Annotation Clustering" +]', single => 1), synchronize => 0}); my $retries = 100; while ($retries-- and ! $mech->is_visible( xpath => '//*[@value="Funct +ional Annotation Clustering"]' )) { sleep 1; $mech->back; } die "Timeout" unless $retries; my $dataurl; my @tab_info = $ff->openTabs(); foreach my $tab(@tab_info) { if ($tab->{location} =~ 'http://david.abcc.ncifcrf.gov/term2term.j +sp?') { $dataurl = $tab->{location}; chomp $dataurl; } } $mech->get($dataurl); my $w = new WWW::Scripter; my @foundLinks = $mech->find_all_links(); my $filelink; foreach my $link(@foundLinks) { if (index($link->[0], ".txt") > 0) { $filelink = $link->[0]; } } $w->get($filelink); if ($w->success()) { my $content = $w->response->content; open(FILE, ">DAVID.txt"); print FILE $content; close FILE; } my $var = `wmctrl -l | grep \"DAVID\" | tail -1 | cut -f1 -d\" \"`; chomp $var; system("wmctrl -i -c \"$var\"");
|
|---|