How to get all the elements of a web page

12,573 views
Skip to first unread message

Raihan

unread,
Apr 13, 2011, 1:28:02 PM4/13/11
to Selenium Users
HI All,

I went to get all the elements(Like Link, Button,lebel, inage etc) in
a html file using web driver. How can i get that using which java
command

Thanks
Raihan

Lutfi Dughman

unread,
Apr 14, 2011, 7:18:54 PM4/14/11
to seleniu...@googlegroups.com
using javascript you can do the following


document.getAllElementsByTagName("input")  <-- you get all inputs
document.getAllElementsByTagName("a")  <-- you get all links
document.getAllElementsByTagName("img")  <-- you get all images

so on and so on


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


Luke Inman-Semerau

unread,
Apr 14, 2011, 7:43:52 PM4/14/11
to seleniu...@googlegroups.com, seleniu...@googlegroups.com
WebDriver does it a bit differently than Se RC. 

With java:
WebDriver driver = new FirefoxDriver();

List<WebElement> inputs = driver.findElementsBy(By.tagName("input"));
List<WebElement> links = driver.findElementsBy(By.tagName("a"));
Etc...

Also please use the webdriver mailing list: webd...@googlegroups.com

-Luke

Lutfi Dughman

unread,
Apr 14, 2011, 8:04:21 PM4/14/11
to seleniu...@googlegroups.com
since webdriver is being integrated with selenium, an overlap in questions and inquiries is inevitable.

Raihan

unread,
Apr 27, 2011, 4:53:28 PM4/27/11
to Selenium Users
Dear All,
Thanks for the suggestions.

List<WebElement> links = driver.findElementsBy(By.tagName("a"));
Just need another suggestion . Some links return empty string if use
getText();How can i find the the text anr url for all the link

On Apr 15, 2:04 am, Lutfi Dughman <lutf...@gmail.com> wrote:
> since webdriver is being integrated with selenium, an overlap in questions
> and inquiries is inevitable.
>
> On Thu, Apr 14, 2011 at 7:43 PM, Luke Inman-Semerau
> <luke.seme...@gmail.com>wrote:
>
>
>
>
>
>
>
> > WebDriver does it a bit differently than Se RC.
>
> > With java:
> > WebDriver driver = new FirefoxDriver();
>
> > List<WebElement> inputs = driver.findElementsBy(By.tagName("input"));
> > List<WebElement> links = driver.findElementsBy(By.tagName("a"));
> > Etc...
>
> > Also please use the webdriver mailing list: <webd...@googlegroups.com>
> > webd...@googlegroups.com
>
> > -Luke
>
> > On Apr 14, 2011, at 4:18 PM, Lutfi Dughman <lutf...@gmail.com> wrote:
>
> > using javascript you can do the following
>
> > document.getAllElementsByTagName("input")  <-- you get all inputs
> > document.getAllElementsByTagName("a")  <-- you get all links
> > document.getAllElementsByTagName("img")  <-- you get all images
>
> > so on and so on
>
> > On Wed, Apr 13, 2011 at 1:28 PM, Raihan < <raihan1...@gmail.com>
> > raihan1...@gmail.com> wrote:
>
> >> HI All,
>
> >> I went to get all the elements(Like Link, Button,lebel, inage etc) in
> >> a html file using web driver. How can i get that using which java
> >> command
>
> >> Thanks
> >> Raihan
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Selenium Users" group.
> >> To post to this group, send email to <seleniu...@googlegroups.com>
> >> seleniu...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> <selenium-users%2Bunsu...@googlegroups.com>

Lutfi Dughman

unread,
Apr 27, 2011, 5:17:33 PM4/27/11
to seleniu...@googlegroups.com
try using xpath to locate the link, give us the html we would would able to help you more on it.

the xpath would look something like this


//DIV[@id='someId']//A[@class='someClass']

Raihan -Ul - Islam

unread,
Apr 27, 2011, 5:19:28 PM4/27/11
to seleniu...@googlegroups.com
thanks . I am just trying facebook  to navigate automatically using java

Lutfi Dughman

unread,
Apr 27, 2011, 5:21:34 PM4/27/11
to seleniu...@googlegroups.com
still, without the html for the exact link you are looking for, i will not be of much help.

Raihan -Ul - Islam

unread,
Apr 27, 2011, 5:23:18 PM4/27/11
to seleniu...@googlegroups.com
Its the home page after you login in facebook

On Wed, Apr 27, 2011 at 11:21 PM, Lutfi Dughman <lut...@gmail.com> wrote:
still, without the html for the exact link you are looking for, i will not ookbe of much help.

Lutfi Dughman

unread,
Apr 27, 2011, 5:37:35 PM4/27/11
to seleniu...@googlegroups.com
lol, i dont use facebook, so i would never log into it ;)

Luke Inman-Semerau

unread,
Apr 27, 2011, 6:40:27 PM4/27/11
to seleniu...@googlegroups.com
for (WebElement el : links) {
  String text = el.getText();
  String href = el.getAttribute("href");

Luke Inman-Semerau

unread,
Apr 27, 2011, 6:41:26 PM4/27/11
to seleniu...@googlegroups.com
whoops... sorry, didn't mean to send that
Reply all
Reply to author
Forward
0 new messages