1

I want to click on the find button to get address list for that I have used className to find element but it is not working.

Code I have written.

driver.findElement(By.className("secondary right postfix findaddress")).click(); 

I have also tried using below code but it is not working. I am getting Timed out after 20 seconds waiting for presence of element located by: By.className: secondary right postfix findaddress

WebDriverWait wait4 = new WebDriverWait(driver,20);
WebElement radio4 = wait4.until(ExpectedConditions.presenceOfElementLocated(By.className("secondary right postfix findaddress")));
((JavascriptExecutor)driver).executeScript("arguments[0].click()", radio4);

HTML code

<div class="small-3 columns">

<button class="secondary right postfix findaddress" style="border-left-color: currentColor !important; border-left-width: medium !important; border-left-style: none !important;" onclick="cmss.addressLookup.search($(this).closest('div.addressSearch'))" type="button">Find</button>

</div>

Once find button clicked select address from dropdown list.

<select class="AddressList" id="CurrentCriteria__addressLst">
<option>- Select -</option><option id="0" name="0">   I can't see my address    </option>
<option id="1" name="1"> 2  Abbot Gardens Essex IG5 7BB</option>
<option id="2" name="2"> 3  Abbot Gardens Essex IG5 7BB </option>

Can anyone help me?

3 Answers3

1

Actually By.className does not support compound class, Try using By.cssSelector as below :-

driver.findElement(By.cssSelector("button.secondary.right.postfix.findaddress")).click(); 
Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73
  • Code for button clicked is working fine. Can you please give me solution on how to select element from dropdown. I have updated the question. – Prashant Bellale Aug 05 '16 at 09:26
  • @PrashantBellale [Have look on this](http://stackoverflow.com/questions/20138761/how-to-select-a-dropdown-value-in-selenium-webdriver-using-java) to select value from dropdown – Saurabh Gaur Aug 05 '16 at 09:31
  • @SubhashGaur This what I have written `Select currentaddresslist = new Select(driver.findElement(By.id("CurrentCriteria__addressLst"))); currentaddresslist.selectByVisibleText("2 Abbot Gardens Essex IG5 7BB"); ` but address is not getting selected. – Prashant Bellale Aug 05 '16 at 10:43
  • @PrashantBellale in your dropdown options text lot of extra white spaces presents may be that's why your are in trouble try using `currentaddresslist.selectByIndex(2);`..Hope it works..:) – Saurabh Gaur Aug 05 '16 at 10:57
0

You have used the locator By.className("secondary right postfix findaddress"), className locator can only be used if there is only 1 class.

Here in your case there are total 4 different classes, hence the locator that you have used wouldn't work.

You can go ahead with any of the below locator:-

driver.findElement(By.cssSelector("button.secondary.right.postfix.findaddress")).click(); 

OR

driver.findElement(By.xpath("//button[@class='secondary right postfix findaddress']")).click();

OR

driver.findElement(By.xpath("//div/button")).click();
Paras
  • 3,197
  • 2
  • 20
  • 30
0

Try this..

driver.findElement(By.xpath("//button[@type = 'button' and contains(@class,'secondary right postfix findaddress') and contains(text(), 'Find')]"))
SOAlgorithm
  • 407
  • 1
  • 5
  • 15