因此,我遇到的問題是我正在計算有多少項(有8個)在導航中菜單https://www.softrams.com/和邏輯將無法正確拉動。要麼我使用了錯誤的功能,要麼我沒有正確編碼它。使用Java和or Python編寫測試以在導航菜單中傳遞/失敗項目數
我爲這個函數的代碼是
WebElement nav_menu_count = driver.findElement(By.xpath("//ul[contains(@class,'nav navbar-nav')]"));
System.out.println(nav_menu_count.getSize());
String nav_count = "710, 51";
if(nav_menu_count.equals(nav_count))
System.out.println("Menu count is correct");
else
System.out.println("Menu count is incorrect");
我的控制檯輸出,當我運行這段代碼是:
(710,51)菜單計數是不正確
使用driver.findElements代替(複數形式)並將其存儲在一個列表。然後使用size()來代替。 getSize()會讓你看到第一個菜單的左上角。 –
Grasshopper
你不能使用'equals()'來測試一個'WebElement'是否等於'String'。這是比較蘋果和西瓜。 – Kayaman