我是Selenium Webdriver的新手。我想从Ul类中提取值并将其存储在变量中,但我无法这样做
这就是我尝试过的 WebElement testuser = driver.findElement(By.cssSelector(“。box ul.form li:nth-child(4)”));
div class =“ box” ul class =“ form”
<li><h4>First Name</h4></li>
<li>Faleata</li>
说无法找到元素
答案 0 :(得分:2)
要处理动态元素,请使用WebDriverWait
,然后尝试以下xpath
。
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='box']/ul[@class='form']//li[./h4[text()='First Name']]/following::li[1]")));
System.out.println(element.getText());
答案 1 :(得分:1)
您可以尝试下面的代码
WebDriverWait waitElmt = new WebDriverWait(driver, 60);
WebElement element = waitElmt.until(ExpectedConditions.elementToBeClickable(By.xpath("(//ul[@class='form']//li)[4]")));
String getText = element.getText();
System.out.println(getText);
答案 2 :(得分:1)
您可以使用下面给出的以下代码段
WebDriverWait waitforelement = new WebDriverWait(driver, 30);
string elementpath = "//div[@class='box']//child::ul[@class='form']//child::li[4]";
WebElement firstname = wait.until(ExpectedConditions.elementToBeClickable
(By.xpath(elementpath)));
System.out.println(firstname.getText());
答案 3 :(得分:1)
我更喜欢使用selenium.support软件包,有很多不错的功能
这很简单:
<item>
<shape android:shape="rectangle" >
<padding
android:left="2dp"
android:top="2dp" />
<solid android:color="@android:color/holo_red_dark" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<padding android:right="2dp" />
<solid android:color="@android:color/holo_blue_dark" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<padding android:bottom="2dp" />
<solid android:color="@android:color/white" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<solid android:color="@android:color/holo_green_light" />
</shape>
</item>
还有很多