我正在将第1期的代码转换为第2期,并且能够找到任何容易的办法来选择一个贴上 down缩的标签,或获得降幅的选定价值。 你们是否知道如何在 Sel2中做到这一点?
这里有两项声明,分别载于第1期,但并非第2期。
browser.select("//path_to_drop_down", "Value1");
browser.getSelectedValue("//path_to_drop_down");
我正在将第1期的代码转换为第2期,并且能够找到任何容易的办法来选择一个贴上 down缩的标签,或获得降幅的选定价值。 你们是否知道如何在 Sel2中做到这一点?
这里有两项声明,分别载于第1期,但并非第2期。
browser.select("//path_to_drop_down", "Value1");
browser.getSelectedValue("//path_to_drop_down");
driver.findElement(By.id("id_dropdown_menu")).click();
driver.findElement(By.xpath("xpath_from_seleniumIDE")).click();
加入:
module Selenium
module WebDriver
class Element
def select(value)
self.find_elements(:tag_name => "option").find do |option|
if option.text == value
option.click
return
end
end
end
end
end
并且你将能够选择价值:
browser.find_element(:xpath, ".//xpath").select("Value")
使用:
selenium.select("id=items","label=engineering")
或
selenium.select("id=items","index=3")
A similar option to what was posted above by janderson would be so simply use the .GetAttribute method in selenium 2. Using this, you can grab any item that has a specific value or label that you are looking for. This can be used to determine if an element has a label, style, value, etc. A common way to do this is to loop through the items in the drop down until you find the one that you want and select it. In C#
int items = driver.FindElement(By.XPath("//path_to_drop_Down")).Count();
for(int i = 1; i <= items; i++)
{
string value = driver.FindElement(By.XPath("//path_to_drop_Down/option["+i+"]")).GetAttribute("Value1");
if(value.Conatains("Label_I_am_Looking_for"))
{
driver.FindElement(By.XPath("//path_to_drop_Down/option["+i+"]")).Click();
//Clicked on the index of the that has your label / value
}
}
you can do like this :
public void selectDropDownValue(String ValueToSelect)
{
webelement findDropDownValue=driver.findElements(By.id("id1")) //this will find that dropdown
wait.until(ExpectedConditions.visibilityOf(findDropDownValue)); // wait till that dropdown appear
super.highlightElement(findDropDownValue); // highlight that dropdown
new Select(findDropDownValue).selectByValue(ValueToSelect); //select that option which u had passed as argument
}
This method will return the selected value for the drop down,
public static String getSelected_visibleText(WebDriver driver, String elementType, String value)
{
WebElement element = Webelement_Finder.webElement_Finder(driver, elementType, value);
Select Selector = new Select(element);
Selector.getFirstSelectedOption();
String textval=Selector.getFirstSelectedOption().getText();
return textval;
}
同时
String textval=Selector.getFirstSelectedOption();
element.getText();
Will return all the elements in the drop down.
Select in Selenium WebDriver
The ‘Select’ class in Selenium WebDriver is used for selecting and deselecting the option in a dropdown. The objects of Select type can be initialized by passing the dropdown webElement as parameter to its constructor.
WebElement testDropDown = driver.findElement(By.id("testingDropdown")); Select dropdown = new Select(testDropDown);
选择减员办法
有三个选择从退学到退学的备选办法。
下降。
下降。
输油管
Select a particular value in a dropdown using the methods of Select class in Selenium Select class implement select tag, providing helper methods to select and deselect options.
WebElement dropdownlist = driver.findElement(By.xpath(locator));
Select listbox = new Select(dropdownlist);
2. 选定类别方法的使用,例如:
selectByIndex(int index): Select the option at the given index.
listbox.selectByIndex(2);
selectByVisibleText(java.lang.String text): Select all options that display text matching the argument
listbox.selectByVisibleText(“Date”);
请参阅以下链接,供进行更详细的讨论:here。
这是从下降中选择价值的法律。
The value for selectlocator will be the xpath or name of dropdown box, and for optionLocator will have the value to be selected from the dropdown box.
public static boolean select(final String selectLocator,
final String optionLocator) {
try {
element(selectLocator).clear();
element(selectLocator).sendKeys(Keys.PAGE_UP);
for (int k = 0; k <= new Select(element(selectLocator))
.getOptions().size() - 1; k++) {
combo1.add(element(selectLocator).getValue());
element(selectLocator).sendKeys(Keys.ARROW_DOWN);
}
if (combo1.contains(optionLocator)) {
element(selectLocator).clear();
new Select(element(selectLocator)).selectByValue(optionLocator);
combocheck = element(selectLocator).getValue();
combo = "";
return true;
} else {
element(selectLocator).clear();
combo = "The Value " + optionLocator
+ " Does Not Exist In The Combobox";
return false;
}
} catch (Exception e) {
e.printStackTrace();
errorcontrol.add(e.getMessage());
return false;
}
}
private static RenderedWebElement element(final String locator) {
try {
return (RenderedWebElement) drivers.findElement(by(locator));
} catch (Exception e) {
errorcontrol.add(e.getMessage());
return (RenderedWebElement) drivers.findElement(by(locator));
}
}
Thanks,
Rekha.
Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i < 10000; i++) { String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...
If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...
I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...