我想点击查找按钮获取我使用className
查找元素的地址列表,但它无法正常工作。
我写的代码。
driver.findElement(By.className("secondary right postfix findaddress")).click();
我也尝试使用下面的代码,但它无法正常工作。我在20秒后等待存在元素位于以下时间时出现: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代码
<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>
任何人都可以帮助我吗?
答案 0 :(得分:1)
实际上By.className
不支持复合类,请尝试使用By.cssSelector
,如下所示: -
driver.findElement(By.cssSelector("button.secondary.right.postfix.findaddress")).click();
答案 1 :(得分:0)
您已使用定位器className
,1
定位器只能在只有4
类的情况下使用。
在您的情况下,总共有driver.findElement(By.cssSelector("button.secondary.right.postfix.findaddress")).click();
个不同的类,因此您使用的定位器无法正常工作。
您可以继续使用以下任何定位器: -
driver.findElement(By.xpath("//button[@class='secondary right postfix findaddress']")).click();
OR
driver.findElement(By.xpath("//div/button")).click();
OR
// This
{{ $x }}
// Will become this
<?php echo($x); ?>
答案 2 :(得分:0)
试试这个..
Sub TestCCollectionItemTry()
Dim o As BuryVBAErrorsCS.CCollectionItemTry
Set o = New BuryVBAErrorsCS.CCollectionItemTry
Dim ws As Excel.Worksheet
Debug.Assert Not o.SheetsItemTry(ThisWorkbook.Sheets, "Sheet3366", ws)
Debug.Assert ws Is Nothing
'* sanity check
Set ws = ThisWorkbook.Worksheets.Item("Sheet1")
Debug.Assert Not ws Is Nothing
'* assuming Sheet1 exists
Set ws = Nothing
Debug.Assert o.SheetsItemTry(ThisWorkbook.Sheets, "Sheet1", ws)
Debug.Assert Not ws Is Nothing
Set ws = Nothing
Debug.Assert o.SheetsItemTry(ThisWorkbook.Sheets, 1, ws)
Debug.Assert Not ws Is Nothing
'* workbooks
Dim wb As Excel.Workbook
Debug.Assert o.WorkbooksItemTry(Application.Workbooks, 1, wb)
Debug.Assert Not wb Is Nothing
Set wb = Nothing
Debug.Assert o.WorkbooksItemTry(Application.Workbooks, ThisWorkbook.Name, wb)
Debug.Assert Not wb Is Nothing
Set wb = Nothing
Debug.Assert Not o.WorkbooksItemTry(Application.Workbooks, "BonzoDogDoodah.xls", wb)
Debug.Assert wb Is Nothing
End Sub