- gaveyomAmateur
- Posts : 38
Join date : 2011-07-13
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
please provide me inscript how to get the links only from left panel
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
- faramkaProfessional
- Posts : 143
Join date : 2011-09-15
Location : Poland
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"));
- gaveyomAmateur
- Posts : 38
Join date : 2011-07-13
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
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
- faramkaProfessional
- Posts : 143
Join date : 2011-09-15
Location : Poland
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.
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.
- gaveyomAmateur
- Posts : 38
Join date : 2011-07-13
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
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.
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
at
at
at
at
************************************************************
please let me know y this error is showing
- faramkaProfessional
- Posts : 143
Join date : 2011-09-15
Location : Poland
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
- gaveyomAmateur
- Posts : 38
Join date : 2011-07-13
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
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
- faramkaProfessional
- Posts : 143
Join date : 2011-09-15
Location : Poland
Re: Urgent --- how to get links under specific panel/ div/ table
Tue Nov 22, 2011 9:16 pm
There is goBack() and goBackAndWait() method in Selenium.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
You can use the second method or, if it is not available, try use two methods: first goBack() and then waitForPageToLoad().
Read the documentation You'll find there answers for most questions
http://release.seleniumhq.org/selenium-remote-control/0.9.2/doc/dotnet/Selenium.ISelenium.GoBack.html
- gaveyomAmateur
- Posts : 38
Join date : 2011-07-13
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
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
- faramkaProfessional
- Posts : 143
Join date : 2011-09-15
Location : Poland
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?
- gaveyomAmateur
- Posts : 38
Join date : 2011-07-13
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
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
- faramkaProfessional
- Posts : 143
Join date : 2011-09-15
Location : Poland
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
Let me know if you solved the problem.
Let me know if you solved the problem.
- gaveyomAmateur
- Posts : 38
Join date : 2011-07-13
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
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
- gaveyomAmateur
- Posts : 38
Join date : 2011-07-13
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
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
- faramkaProfessional
- Posts : 143
Join date : 2011-09-15
Location : Poland
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:
If you want to localize, for example, the third link in this div, the code will look like this:
But certainly you can do it in this way:
- Code:
//div[@id='content']/a[1]
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]
- gaveyomAmateur
- Posts : 38
Join date : 2011-07-13
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
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.
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
at
at
at
at
************************************************************
please let me know y this issue is getting
thank you
- faramkaProfessional
- Posts : 143
Join date : 2011-09-15
Location : Poland
Re: Urgent --- how to get links under specific panel/ div/ table
Wed Nov 23, 2011 9:17 pm
If it works with two slashes before a, trydriver.findElement(By.xpath("//div[@id='Menutagname1_TreeView1']//a[@id='linkId']")).click();
- 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.
- gaveyomAmateur
- Posts : 38
Join date : 2011-07-13
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
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
- faramkaProfessional
- Posts : 143
Join date : 2011-09-15
Location : Poland
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...
Sorry, I have no more ideas...
- gaveyomAmateur
- Posts : 38
Join date : 2011-07-13
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
thank you for your quick and continuous support
i will google it for this
once again thanks a lot
Permissions in this forum:
You cannot reply to topics in this forum