英文:
Is there a Selenium method to verify what it is written in a drop down box?
问题
以下是您要翻译的内容:
我已经尝试验证在使用拖放操作移动元素后,下拉框中的内容。我尝试使用selectByVisibleText()
方法,但我意识到这个方法并不相关。是否有人知道在Selenium中是否有适合我描述的方法?
以下是我的代码:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
public class DragAndDrop {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","/Chromedriver/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://formy-project.herokuapp.com/dragdrop");
WebElement seleniumLogo = driver.findElement(By.id("image"));
WebElement box = driver.findElement(By.id("box"));
Actions actions = new Actions(driver);
actions.dragAndDrop(seleniumLogo, box).build().perform();
new Select(driver.findElement(By.id("box"))).selectByVisibleText("");
// driver.quit();
}
}
英文:
I have tried to verify what it is written in a drop down box after the element is moved with drag and drop. I have tried using the selectByVisibleText()
method but I realized this method is not relevant. Does anybody know if there is a method in Selenium that would fit my description?
Here is my code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
public class DragAndDrop {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","/Chromedriver/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://formy-project.herokuapp.com/dragdrop");
WebElement seleniumLoggo =driver.findElement(By.id("image"));
WebElement box=driver.findElement(By.id("box"));
Actions actions=new Actions(driver);
actions.dragAndDrop(seleniumLoggo,box).build().perform();
new Select( driver.findElement(By.id("box")).selectByVisibleText());
// driver.quit();
}
}
答案1
得分: 0
这实际上很简单(虽然可能不太直观)- 只需在元素上调用 getText()
:
String theText = driver.findElement(By.id("box")).getText();
英文:
It's actually trivial (though probably not very intuitive) - just call getText()
on the element:
String theText = driver.findElement(By.id("box")).getText();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论