Selenium webdriver 无法使用selenium webdriver单击按钮并从下拉列表中选择元素

Selenium webdriver 无法使用selenium webdriver单击按钮并从下拉列表中选择元素,selenium-webdriver,Selenium Webdriver,我想点击find按钮来获取地址列表,我已经使用className来查找元素,但它不起作用 我写的代码 driver.findElement(By.className("secondary right postfix findaddress")).click(); 我也尝试过使用下面的代码,但它不起作用。我在等待位于by:by.className:secondary right postfix findaddress的元素出现20秒后超时 WebDriverWait wait4 = new W

我想点击find按钮来获取地址列表,我已经使用
className
来查找元素,但它不起作用

我写的代码

driver.findElement(By.className("secondary right postfix findaddress")).click(); 
我也尝试过使用下面的代码,但它不起作用。我在等待位于by:by.className:secondary right postfix findaddress的元素出现20秒后超时

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代码

<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>

发现
单击“查找”按钮后,从下拉列表中选择地址

<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>

-选择-我看不到我的地址
艾塞克斯艾伯特花园2号IG5 7BB
艾塞克斯艾伯特花园3号IG5 7BB

有人能帮我吗?

实际上
By.className
不支持复合类,请尝试使用
By.cssSelector
,如下所示:-

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

您已通过.className(“次右后缀findaddress”)使用了定位器
className
定位器只能在只有
1
类的情况下使用

在您的示例中,总共有4个不同的类,因此您使用的定位器无法工作

您可以继续使用以下任何定位器:-

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

试试这个

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

单击按钮的代码工作正常。你能给我一个如何从下拉列表中选择元素的解决方案吗。我已经更新了问题。@PrashantBellale从中选择值dropdown@SubhashGaur这就是我所写的
selectcurrentAddressList=newselect(driver.findElement(By.id)(“currentCriterias\uuu addressLst”));当前地址列表。通过可视文本选择(“2 Abbot Gardens Essex IG5 7BB”)但未选择地址。@PrashantBellale在您的下拉选项文本中可能会出现大量额外的空格,这就是您遇到问题的原因。请尝试使用
currentaddresslist.selectByIndex(2)。希望它能工作:)
driver.findElement(By.xpath("//div/button")).click();
driver.findElement(By.xpath("//button[@type = 'button' and contains(@class,'secondary right postfix findaddress') and contains(text(), 'Find')]"))