Reputation: 35
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?
Upvotes: 1
Views: 1789
Reputation: 425
Try this..
driver.findElement(By.xpath("//button[@type = 'button' and contains(@class,'secondary right postfix findaddress') and contains(text(), 'Find')]"))
Upvotes: 0
Reputation: 3235
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();
Upvotes: 0
Reputation: 23805
Actually By.className
does not support compound class, Try using By.cssSelector
as below :-
driver.findElement(By.cssSelector("button.secondary.right.postfix.findaddress")).click();
Upvotes: 1