【发布时间】:2017-06-25 02:42:22
【问题描述】:
当尝试点击亚马逊网站中的 Signout 时,会显示错误消息“元素应该是“选择”但原来是“div”。看起来 CSS 选择器和 XPATH 标识符中的任何一个最终都不起作用代码。请帮助解决这个问题。
import java.sql.Driver;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
public class FirstClass {
private static final String SeleniumWait = null;
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Documents\\Selenium\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.amazon.com/");
driver.findElement(By.id("nav-link-accountList")).click();
driver.findElement(By.id("ap_email")).sendKeys("welcom@gmail.com");
driver.findElement(By.id("ap_password")).sendKeys("Password");
driver.findElement(By.id("signInSubmit")).click();
driver.findElement(By.xpath("//*[@id='nav-link-accountList']/span[1]")).click();
//driver.findElement(By.xpath("//*[@id='nav-al-container']")).click();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(0, 50);");
Select dropdown = new Select(driver.findElement(By.xpath("//*[@id='nav-al-container']")));
dropdown.selectByVisibleText("Not test? Sign Out");
WebDriverWait wait = new WebDriverWait(driver, 40);// 1 minute
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("//*[@id='nav-item-signout']/span")));
driver.findElement(By.cssSelector("#nav-item-signout > span")).click();//CSS selector
//driver.findElement(By.xpath("//*[@id='nav-item-signout']/span")).click(); //XPATH
【问题讨论】:
标签: selenium-webdriver element