我使用Selenium WebDriver我需要对第一个帐户项执行和操作(单击),执行某些操作,然后返回并在下一个项目上重复该过程。它最多可能包含90个帐户项目,因此我试图避免对所有90个帐户进行硬编码。任何想法如何绕过帐户列表?
<ul class="account-list">
<li class="account-item">one item</li>
<li class="account-item">two items</li>
<li class="account-item">three items</li>
</ul>
&#13;
答案 0 :(得分:1)
你不能迭代Selenium中的元素列表,因为当DOM更改时,它们的对象引用将变为无效(StaleElement异常),但是只要列表的大小不是这样,你就可以通过索引号来完成它改变
elements = @driver.find_elements(css: ".account-item>a")
elements.size.times do |i|
@driver.find_element(css: ".account-list > li:nth-child(#{i})>a").click
# Do something
@driver.navigate.back
end
答案 1 :(得分:0)
你可以通过import java.util.Scanner;
public class Fibonacci {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
System.out.println("This is a Fibonacci sequence generator");
System.out.println("Choose what you would like to do");
System.out.println("1. Find the nth Fibonacci number");
System.out.println("2. Find the smallest Fibonacci number that exceeds user given value");
System.out.println("3. Find the two Fibonacci numbers whose ratio is close enough to the golden number");
System.out.print("Enter your choice: ");
int choice = scan.nextInt();
int xPre = 0;
int xCurr = 1;
int xNew = 0;
switch (choice)
{
case 1:
System.out.print("Enter the target index to generate (>1): ");
int index = scan.nextInt();
for (int i = 2; i <= index; i++)
{
xNew = xPre + xCurr;
xPre = xCurr;
xCurr = xNew;
}
System.out.println("The " + index + "th number Fibonacci number is " + xNew);
break;
case 2:
System.out.print("Enter the target value (>1): ");
int value = scan.nextInt();
}
}
}
获取所有元素,然后按照以下方式迭代元素来实现:
css