簡體   English   中英

無法使用 selenium webdriver 在 Gmail 中單擊撰寫按鈕

[英]Unable to click on compose button in Gmail using selenium webdriver

我的代碼是:

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 顯示無法定位元素或復合類被禁止錯誤。

這個 xpath "//div[@id=':ii']/div/div" OR .//div[normalize-space()='COMPOSE']為我點擊撰寫按鈕。

嘗試這個

driver.findElement(By.xpath("//div[@id=':ii']/div/div"));

或者

driver.findElement(By.xpath(".//div[normalize-space()='COMPOSE']"));

我在 WATIR 中編寫了下面給出的程序並檢查了它,它可以工作,你可以在你的程序中使用相同的定位器,你可以執行它。

b.goto("www.gmail.com")
b.a(:text, "Sign In").click
b.element(:id, "identifierId").send_keys "sharmi.paul87@gmail.com"
b.element(:css, "#identifierNext > content.CwaK9 > span.RveJvd.snByac").click
b.element(:name, "password").send_keys "pramilapaul"
b.element(:css, "span.RveJvd.snByac").click
b.element(:xpath, "//div[@id=':ii']/div/div").click

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM