因此,我遇到的问题是我正在计算有多少项(有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