如何使用java和selenium引用以下html元素?
我想使用java访问以下元素,其中只有一个值指示符。 在name=“txnSource”下,使用选项值标识的所有文本值都是可以从下拉选择器中进行的选择 我想从下拉框中自动选择值,这就是为什么我需要知道如何访问值。。。 没有“findElement(By.value(“value”)”),所以如何通过值访问元素 我认为通过xpath进行访问会非常不稳定。此外,下拉列表中选项的任何更改都需要对xpath标识进行整体修改如何使用java和selenium引用以下html元素?,java,html,xpath,selenium,automation,Java,Html,Xpath,Selenium,Automation,我想使用java访问以下元素,其中只有一个值指示符。 在name=“txnSource”下,使用选项值标识的所有文本值都是可以从下拉选择器中进行的选择 我想从下拉框中自动选择值,这就是为什么我需要知道如何访问值。。。 没有“findElement(By.value(“value”)”),所以如何通过值访问元素 我认为通过xpath进行访问会非常不稳定。此外,下拉列表中选项的任何更改都需要对xpath标识进行整体修改 在Java中,我认为应该是这样的 IWebElement dropDownLis
在Java中,我认为应该是这样的
IWebElement dropDownListBox = driver.findElement(By.Name("txnSource"));
SelectElement clickThis = new SelectElement(dropDownListBox);
clickThis.SelectByValue("500");
在Ruby中就是这样做的
Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "txnSource")).select_by(:value, "500")
在Java中,我认为应该是这样的
IWebElement dropDownListBox = driver.findElement(By.Name("txnSource"));
SelectElement clickThis = new SelectElement(dropDownListBox);
clickThis.SelectByValue("500");
在Ruby中就是这样做的
Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "txnSource")).select_by(:value, "500")
在Java中,您可以执行以下任一操作:
driver.findElement(By.cssSelector("option[value='500']")).click();
或
或使用
在Java中,您可以执行以下任一操作:
driver.findElement(By.cssSelector("option[value='500']")).click();
或
或使用
您可以像这样从拾取列表中选择一个选项
new Select(driver.findElement(By.name("txnSource"))).selectByVisibleText("Text- Stock Movement (DOGS)");
您可以像这样从拾取列表中选择一个选项
new Select(driver.findElement(By.name("txnSource"))).selectByVisibleText("Text- Stock Movement (DOGS)");