0
votes

I'm trying to test search UI using selenium web driver in java
If I click on result it shows some properties of that results.
So now when I click on first result, the webdriver is able to locate those properties by FindElementsByXpath("//li[@class='clickable ng-binding ng-scope']")
Also tried findElementsByCss("*[class='clickable ng-binding ng-scope']")
But when webdriver clicks on second result, it shows up their properties but webdriver is UNABLE to locate properties (have same class name as first).

Any help here?
can't use Xpath since ids are unique and different.
First result clicked


Second result clicked

i click result using this-

findElement(By.xpath("/html/body/div[1]/div/div/div[1]/div[2]/div[1]/div[2]/div/els-result["+num+"]/div")).click(); 

where num is result number
*Stack trace here

org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of all elements located by By.cssSelector: *[class='clickable ng-binding ng-scope'] (tried for 15 second(s) with 500 MILLISECONDS interval) Build info: version: '3.1.0', revision: '86a5d70', time: '2017-02-16 07:57:44 -0800' System info: host: '', ip: '', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.3', java.version: '1.8.0_121' Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, appBuildId=20170125094131, version=, platform=MAC, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, processId=22487, browserVersion=51.0.1, platformVersion=16.4.0, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=darwin, firefox_profile=UEsDBBQACAgIAOl6aUoAAAAAAAAAA..., unexpectedAlertBehaviour=dismiss}] Session ID: df2df541-1966-5a4b-871c-7cd8c295f4eb at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:257) at cucumber.stepdefination.DataSearch.FindElementsByCss(DataSearch.java:166) at cucumber.stepdefination.AssestCountSD.assest_count_matches_list(AssestCountSD.java:76) at cucumber.stepdefination.AssestCountSD.for_each_source_assest_count_matches_that_in_list_on_right(AssestCountSD.java:51) at ✽.Then For each source assest count matches that in list on right(/Users/malikh/Documents/workspace/cucumber/src/test/resource/assetCount.feature:6)

1
what about FindElementsByCss(".clickable.ng-binding.ng-scope") - eLRuLL
@eLRuLL this is also giving timeout error. This also worked for first result but didn't for second result - insomniac
@Dillanm added HTML too - insomniac
can you change FindElementsByCss to FindElementByCss and try ? - NarendraR
@All I have found a way around - that is to refresh page every time before clicking next result. It is able to locate elements then BUT refresh is an overhead and takes up a lot of time. Any idea what's wrong? - insomniac

1 Answers

0
votes

I would suggest to use Firefox browser and install one of its extensions called 'Firepath'. This would help you to locate a UI element using both 'Xpath' and 'CSS'.