Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
gaveyom
Amateur
Amateur
Posts : 38
Join date : 2011-07-13

Urgent --- how to get links under specific panel/ div/ table Empty Urgent --- how to get links under specific panel/ div/ table

Fri Nov 04, 2011 11:38 am
Hi All,

i am new to selenium

i want to get all the links under specific panel/ div/ table

for example
-----------

there is left panel and right panel, both panels having some links

now i wanna get only the links from left panel

currently i am using the below code but this code is giving all the links from left and right panel

List links = driver.findElements(By.TagName("a"));
System.out.println(links.size())

but i wanna get only the links from left panel
for example the left panel is existing under div tag like

for example a page containing the below code

Code:
<div id="left_Panel">
    <a href="left1"> Left1 </a>
    <a href="left2"> Left2 </a>
    <a href="left3"> Left3 </a>
</div>

<div id="right_Panel">
    <a href="right1"> Right1 </a>
    <a href="right2"> Right2 </a>
    <a href="right3"> Right3 </a>
</div>

please provide me inscript how to get the links only from left panel
avatar
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Fri Nov 04, 2011 4:44 pm
I am not a Java developer, but I think you can try something like this:
Code:
List links = driver.findElements(By.xpath("//div[@id='left_Panel']/a"));
avatar
gaveyom
Amateur
Amateur
Posts : 38
Join date : 2011-07-13

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Tue Nov 22, 2011 1:50 pm
Hi faramka,

its working fine thank you very much

i have 1 question, using " xpath " is not good as per my knowledge and what i have studied on forums

is there any other way to get the solution instead of using " xpath "

once again thanks a lot

please let me know if there is any solution for this
avatar
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Tue Nov 22, 2011 2:30 pm
Here is an article about Selenium locators http://www.qaautomation.net/?p=188
Read it and choose the best way for you.
There is always risk that xPath (and CSS or locators of any other type) will be changed. This is a fact which you are not able to avoid.
avatar
gaveyom
Amateur
Amateur
Posts : 38
Join date : 2011-07-13

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Tue Nov 22, 2011 7:16 pm
Hi Faramka,

thanks a lot.

when i execute the script, i got all the links

now i try to click each link 1 by 1

it is clicking 1st link but after clicking the 1st link it is showing the below error

please look into this


************************************************************

Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: Element not found in the cache
Build info: version: '2.0.0', revision: '12817', time: '2011-07-07 19:13:58'
System info: os.name: 'Windows NT (unknown)', os.arch: 'x86', os.version: '6.1', java.version: '1.5.0_05'
Driver info: driver.version: RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:131)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:105)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:402)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:213)
at org.openqa.selenium.remote.RemoteWebElement.getText(RemoteWebElement.java:117)
at sample.(sample.java:51)
at sample.main(sample.java:18)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Element not found in the cache
Build info: version: '2.0.0', revision: '12817', time: '2011-07-07 19:13:58'
System info: os.name: 'Windows NT (unknown)', os.arch: 'x86', os.version: '6.1', java.version: '1.5.0_05'
Driver info: driver.version: unknown
at .(resource://fxdriver/modules/utils.js:7725)
at .(file:///C:/Users/SIVAKU~1/AppData/Local/Temp/anonymous45113webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js -> file:///C:/Users/SIVAKU~1/AppData/Local/Temp/anonymous45113webdriver-profile/extensions/fxdriver@googlecode.com/components/wrappedElement.js:147)
at .(file:///C:/Users/SIVAKU~1/AppData/Local/Temp/anonymous45113webdriver-profile/extensions/fxdriver@googlecode.com/components/nsCommandProcessor.js:306)
at .(file:///C:/Users/SIVAKU~1/AppData/Local/Temp/anonymous45113webdriver-profile/extensions/fxdriver@googlecode.com/components/nsCommandProcessor.js:320)
at .(file:///C:/Users/SIVAKU~1/AppData/Local/Temp/anonymous45113webdriver-profile/extensions/fxdriver@googlecode.com/components/nsCommandProcessor.js:197)

************************************************************

please let me know y this error is showing
avatar
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Tue Nov 22, 2011 7:27 pm
Check this http://osdir.com/ml/selenium-users/2011-08/msg01497.html
avatar
gaveyom
Amateur
Amateur
Posts : 38
Join date : 2011-07-13

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Tue Nov 22, 2011 8:14 pm
Hi faramka,

thank u very much it got the solution

1 more question to u, how to click the browser back button

i wanna go to previous page from the current page

is there any method to go previous page in browser for " WebDriver " and please let me know is there any implic wait method to wait untill page get generated without using any condition

please let me know if there is any such method

thanks in advance
avatar
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Tue Nov 22, 2011 9:16 pm
gaveyom wrote:1 more question to u, how to click the browser back button

i wanna go to previous page from the current page

is there any method to go previous page in browser for " WebDriver " and
please let me know is there any implic wait method to wait untill page
get generated without using any condition
There is goBack() and goBackAndWait() method in Selenium.
You can use the second method or, if it is not available, try use two methods: first goBack() and then waitForPageToLoad().

Read the documentation Smile You'll find there answers for most questions Smile
http://release.seleniumhq.org/selenium-remote-control/0.9.2/doc/dotnet/Selenium.ISelenium.GoBack.html
avatar
gaveyom
Amateur
Amateur
Posts : 38
Join date : 2011-07-13

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Wed Nov 23, 2011 1:31 pm
Hi faramka,

thanks a lot for your quick replies

im using here " webdriver ", solutions to go back is

--- driver.navigate().back(); ---

now im facing another problem when clicking the links

if there is 2 panels in a page

1. Left Panel
2. Right Panel

here the problem is same link is existing in left and right panel

for example

link name: yahoo

" yahoo" link is having in both the left and right panel

when i try to click the " yahoo" link, it is clicking randomly but i wanna click only the right side panel link

currently im using the below script to click the link

************************************************************
driver.findElement(By.linkText("yahoo")).click();
************************************************************

please let me know how to click the link which is existing in right side panel only

thank in advacne, once again thank u very much for your quick reply
avatar
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Wed Nov 23, 2011 2:35 pm
Can you find elements using something else than linkText? For example href or title? Or just by id or css class?
avatar
gaveyom
Amateur
Amateur
Posts : 38
Join date : 2011-07-13

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Wed Nov 23, 2011 4:00 pm
Hi faramka,

thank you for your reply

here we don't have id's that is the mail problem

here we can differentiate only with left and right panel

im new to this selenium tool, i heard that it is possible possible with xpath, i have tried with many permutations but im not able to get the solution

please let me know if there is any solution to click the link which is under specific panel/ div/ table

thanks in advance
avatar
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Wed Nov 23, 2011 4:22 pm
Do you use Firefox? Install FirePath add-on - you will be able to inspect elements and get their xPath Smile
Let me know if you solved the problem.
avatar
gaveyom
Amateur
Amateur
Posts : 38
Join date : 2011-07-13

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Wed Nov 23, 2011 4:42 pm
Hi faramka,

im able to get xpath but im not able 2 write the syntax

im not getting correct syntax to write how to click the link which is under specific panel/ div/ table

currently im using below script to click the link, below script is generic to click link in a whole page but i want to click under specific panel/ div/ table by using xpath

driver.findElement(By.linkText("yahoo")).click();

please let me know how to write the syntax by using xpath

thank you
avatar
gaveyom
Amateur
Amateur
Posts : 38
Join date : 2011-07-13

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Wed Nov 23, 2011 5:27 pm
Hi faramka,

is it possible to use index option " //div[@id='content']/a[@index='1'] " to click the link instead of " //div[@id='content']/a[@id='linkID'] "

thank you
avatar
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Wed Nov 23, 2011 7:32 pm
I think rather not.

But certainly you can do it in this way:
Code:
//div[@id='content']/a[1]
The above code is pointing to the first link which is found in a div with id = content.
If you want to localize, for example, the third link in this div, the code will look like this:
Code:
//div[@id='content']/a[3]
avatar
gaveyom
Amateur
Amateur
Posts : 38
Join date : 2011-07-13

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Wed Nov 23, 2011 8:02 pm
Hi faramka,

when i use as per above which u have mentioned

my script changed as

driver.findElement(By.xpath("//div[@id='Menutagname1_TreeView1']/a[3]")).click();

but when u use id or name it is working

driver.findElement(By.xpath("//div[@id='Menutagname1_TreeView1']//a[@id='linkId']")).click();

when executing the below error is displaying

***********************************************************


Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//div[@id='Menutagname1_TreeView1']/a[3]"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.0.0', revision: '12817', time: '2011-07-07 19:13:58'
System info: os.name: 'Windows NT (unknown)', os.arch: 'x86', os.version: '6.1', java.version: '1.5.0_05'
Driver info: driver.version: RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:131)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:105)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:402)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:190)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:263)
at org.openqa.selenium.By$ByXPath.findElement(By.java:323)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:182)
at sample.(sample.java:78)
at sample.main(sample.java:40)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {"method":"xpath","selector":"//div[@id='Menutagname1_TreeView1']/a[3]"}
Build info: version: '2.0.0', revision: '12817', time: '2011-07-07 19:13:58'
System info: os.name: 'Windows NT (unknown)', os.arch: 'x86', os.version: '6.1', java.version: '1.5.0_05'
Driver info: driver.version: unknown
at .(file:///C:/Users/SIVAKU~1/AppData/Local/Temp/anonymous58490webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js -> file:///C:/Users/SIVAKU~1/AppData/Local/Temp/anonymous58490webdriver-profile/extensions/fxdriver@googlecode.com/components/firefoxDriver.js:359)
at .(file:///C:/Users/SIVAKU~1/AppData/Local/Temp/anonymous58490webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js -> file:///C:/Users/SIVAKU~1/AppData/Local/Temp/anonymous58490webdriver-profile/extensions/fxdriver@googlecode.com/components/firefoxDriver.js:382)
at .(file:///C:/Users/SIVAKU~1/AppData/Local/Temp/anonymous58490webdriver-profile/extensions/fxdriver@googlecode.com/components/nsCommandProcessor.js:306)
at .(file:///C:/Users/SIVAKU~1/AppData/Local/Temp/anonymous58490webdriver-profile/extensions/fxdriver@googlecode.com/components/nsCommandProcessor.js:320)
at .(file:///C:/Users/SIVAKU~1/AppData/Local/Temp/anonymous58490webdriver-profile/extensions/fxdriver@googlecode.com/components/nsCommandProcessor.js:197)

************************************************************

please let me know y this issue is getting

thank you
avatar
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Wed Nov 23, 2011 9:17 pm
driver.findElement(By.xpath("//div[@id='Menutagname1_TreeView1']//a[@id='linkId']")).click();
If it works with two slashes before a, try
Code:
driver.findElement(By.xpath("//div[@id='Menutagname1_TreeView1']//a[3]")).click();


Install XPath Checker Firefox add-on and check if these paths are correct.
avatar
gaveyom
Amateur
Amateur
Posts : 38
Join date : 2011-07-13

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Wed Nov 23, 2011 10:12 pm
Hi faramka,

i have tried with 2 slashes also but not working

despite i have install the xpath checker it is not working

please let me known y it is not working

thank you
avatar
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Thu Nov 24, 2011 2:42 pm
If XPath Checker tells 'no matches found', there is no element with such path. Are you sure the path is correct? Try get it by 'View xPath' in your context menu.
Sorry, I have no more ideas...
avatar
gaveyom
Amateur
Amateur
Posts : 38
Join date : 2011-07-13

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Thu Nov 24, 2011 4:05 pm
Hi faramka,

thank you for your quick and continuous support

i will google it for this

once again thanks a lot
Sponsored content

Urgent --- how to get links under specific panel/ div/ table Empty Re: Urgent --- how to get links under specific panel/ div/ table

Back to top
Permissions in this forum:
You cannot reply to topics in this forum