我无法通过使用'选择'从下拉列表中选择选项。方法。
这是我的Gmail帐户创建代码。
enter code here
package samples;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;
public class SmallFunctionalities {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
FirefoxDriver driver= new FirefoxDriver();
driver.manage().window().maximize();
Thread.sleep(5000);
driver.get("https://accounts.google.com/SignUp");
Thread.sleep(5000);
Select sitem= new Select(driver.findElement(By.id("BirthMonth")));
sitem.selectByIndex(5);
Thread.sleep(5000);
}
}
线程中的异常" main" org.openqa.selenium.support.ui.UnexpectedTagNameException:元素应该是" select"但是" span"
答案 0 :(得分:0)
它不是下拉值,您必须单击下拉箭头,然后单击您必须从脚本传递的任何值。
代码如下:
System.setProperty("webdriver.chrome.driver", "E:/software and tools/chromedriver_win32/chromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://accounts.google.com/SignUp");
Thread.sleep(5000);
//Click on up/down arrow
driver.findElement(By.xpath(".//*[@id='BirthMonth']/div[1]/div[2]")).click();
// Now select value from list
driver.findElement(By.xpath(".//*[@id=':7']/div")).click();