我是selenium的新手,目前正在研究selenium webdriver我想从下拉列表中选择一个值.id = periodId和选项很多,我试图选择过去52周.
这是Html标签:
<select id="periodId" name="period" style="display: none;">
<option value="l4w">Last 4 Weeks</option>
<option value="l52w">Last 52 Weeks</option>
<option value="daterange">Date Range</option>
<option value="weekrange">Week Range</option>
<option selected="" value="monthrange">Month Range</option>
<option value="yeartodate">Year To Date</option>
</select>
Run Code Online (Sandbox Code Playgroud)
请建议我点击下拉列表的一些方法.
我尝试使用上面的示例行但是得到错误,例如Element当前不可见,因此可能无法与命令持续时间或超时交互:32毫秒下拉值是jquery multiselect小部件格式
目前正在使用Selenium WebDriver并使用Java.我想date range从下拉列表中选择值.我想知道如何选择Date, Month and year日期选择器下拉列表中的值.
这是HTML标记:
<dd id="date-element">
<input id="fromDate" class="hasDatepicker" type="text" style="width:57px; padding:3px 1px; font-size:11px;" readonly="readonly" name="fromDate" value="01 Jan 2013">
<input id="toDate" class="hasDatepicker" type="text" style="width:57px; padding:3px 1px; font-size:11px;" readonly="readonly" name="toDate" value="31 Dec 2013">
Run Code Online (Sandbox Code Playgroud)

我试过以下示例代码:
Log.info("Clicking on From daterange dropdown");
JavascriptExecutor executor8 = (JavascriptExecutor)driver;
executor8.executeScript("document.getElementById('fromDate').style.display='block';");
Select select8 = new Select(driver.findElement(By.id("fromDate")));
select8.selectByVisibleText("10 Jan 2013");
Thread.sleep(3000);
Log.info("Clicking on To daterange dropdown");
JavascriptExecutor executor10 = (JavascriptExecutor)driver;
executor10.executeScript("document.getElementById('toDate').style.display='block';");
Select select10 = new Select(driver.findElement(By.id("toDate")));
select10.selectByVisibleText("31 Dec …Run Code Online (Sandbox Code Playgroud) 我在D:目录中有一个名为/NewFile.xml的XML文件.XML文件包含以下详细信息:
<?xml version="1.0"?>
<project>
<logindetails id="1001">
<url>https:xxx</url>
<username>xxx</username>
<password>xxx</password>
</logindetails >
<kpi id="1001">
<id_r>reports</id_r>
<id_e>extranet</id_e>
<id_pr>ext-pr</id_pr>
</kpi>
<prkpi id="1001">
<id_1>ext-pr-backlog-age</id_1>
<id_2>ext-timetoassign-prs</id_2>
<id_3>ext-timetodeliver-prs</id_3>
<id_4>ext-timetoresolve-prs</id_4>
<id_5>ext-new-prs</id_5>
</prkpi>
<filtersection id="1001">
<visualizationId>Day,Week,Month,Quarter,Semester,Year,RD Tech Group,ICC,Center,Software Pack,Product,Project,Customer PRs,Severity,Priority</visualizationId>
<projectId>dev/v4.3/r4/e12sqq,BATS,1523 Business IAD & Business CPE,[CoCo2M],VQM</projectId>
</filtersection>
</project>Run Code Online (Sandbox Code Playgroud)
我在eclipse中运行的代码如下:
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.w3c.dom.Document;
import …Run Code Online (Sandbox Code Playgroud)我正在测试的页面有2个具有相同名称的元素,我需要单击第二个元素.我可以使用以下方法获取元素:
driver.findElements(By.linkText("Services"));
Run Code Online (Sandbox Code Playgroud)
但我不知道如何click处理第二个元素.
在 selenium webdriver 中,我想在 java 中使用 if/else 条件。每一步都需要检查,需要一一执行。例如
Log.info("Clicking on Reports link");
WebElement menuHoverLink = driver.findElement(By.id("reports"));
actions.moveToElement(menuHoverLink).perform();
Thread.sleep(6000);
Run Code Online (Sandbox Code Playgroud)
在这段代码中,我需要检查 id 一旦它出现就需要执行操作,否则它需要跳过测试用例才不会失败。