【发布时间】:2018-04-28 11:29:25
【问题描述】:
我的代码是:
public class LoginGmail{
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","D:/selenium/chromedriver_win32/chromedriver.exe");
WebDriver fd= new ChromeDriver();
fd.get("https://www.google.com/intl/en_in/gmail/about/");
Thread.sleep(5000);
fd.manage().window().maximize();
WebElement e1=fd.findElement(By.xpath("html/body/nav/div/a[2]"));
e1.click();
WebElement username = fd.findElement(By.xpath(".//*[@id='identifierId']"));
username.sendKeys("sharmi.paul87@gmail.com");
WebElement username_click = fd.findElement(By.xpath(".//*[@id='identifierNext']/content/span"));
username_click.click();
WebDriverWait wait = new WebDriverWait(fd,30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@aria-label=\"Enter your password\"]")));
WebElement password= fd.findElement(By.xpath("//input[@aria-label=\"Enter your password\"]"));
password.sendKeys("pramilapaul");
WebElement password_click = fd.findElement(By.xpath(".//*[@id='passwordNext']/content"));
password_click.click();
/* --------------------------*/
//fd.findElement(By.xpath("//div[contains(text(),'COMPOSE')]")).click();
//WebElement button=fd.findElement(By.xpath("//div[contains(@id,':ir')]"));
//WebElement buttton=fd.findElement(By.xpath("//div[@gh='cm']"));*/
//WebElement button=fd.findElement(By.cssSelector(".aic div[role='button']"));
// button.click();
HTML 代码:
撰写在上面的“/--/”中,任何 xpath 都不起作用。 有人可以帮忙吗? xpath 显示无法定位元素或复合类是禁止的错误。
【问题讨论】:
-
添加HTML代码,这样我们就可以检查Xpath定位器了
-
首先,“在上面的/--/”不是指向代码块的有用指针。告诉我们究竟是什么不起作用。其次,您的问题缺少minimal reproducible example。如果没有 HTML 代码来匹配您的脚本与脚本本身是完全没用的。看到这个:idownvotedbecau.se/nomcve
-
撰写
-
@Sharmila 我已经写了一个答案,你可以检查一下吗?
-
是的,但我回答了。它不工作。
标签: java selenium selenium-webdriver selenium-chromedriver