這就是我想要做的Gmail。無法點擊Gmail中的設置圖標與硒網絡驅動程序
- www.gmail.com使用有效的用戶(如果不存在,創建一個虛擬用戶)
- 登錄
- 點擊收件箱
- 點擊第一封電子郵件
- 單擊編寫電子郵件。
- 發送郵件到同一個電子郵件帳戶。
- 點擊選項圖標右上角
- 了對一般外出回覆設置選項卡
- 選擇外出回覆上。
我可以點擊第一封電子郵件,選擇電子郵件地址,然後點擊撰寫電子郵件按鈕,也可以發送電子郵件。 我面臨的問題是無法點擊設置圖標。該元素被隱藏,我無法點擊它。我用custom-Xpath嘗試了它,並試圖用座標點擊它。 但它不適合我。請任何人都可以幫我解決這個問題。
import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Gmail1 {
public static void main(String[] args) throws InterruptedException {
// Login to browser
WebDriver driver= new FirefoxDriver();
driver.get("https://www.gmail.com");
driver.manage().window().maximize();
System.out.println("Browser opned");
driver.findElement(By.xpath("//*[@id='Email']")).sendKeys("Use your UserId");
System.out.println("Entered Email id");
driver.findElement(By.xpath("//*[@id='next']")).click();
System.out.println("Clicked on Next");
Thread.sleep(3000);
driver.findElement(By.xpath("//*[@id='Passwd']")).sendKeys("Use your password");
System.out.println("Entered the Password");
driver.findElement(By.xpath("//*[@id='signIn']")).click();
System.out.println("Welcome to gmail");
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@id=':3d']")).click();
System.out.println("Clicked on email");
Thread.sleep(3000);
String emailid = driver.findElement(By.xpath("//span[@class='go']")).getText();
emailid=emailid.substring(emailid.indexOf("<")+1, emailid.indexOf(">"));
System.out.println(emailid);
driver.findElement(By.xpath("//*[@id=':it']/div/div")).click();
System.out.println("Clicked on Compose mail");
driver.findElement(By.xpath("//*[@name='to']")).sendKeys(emailid);
System.out.println("Entered the TO Email Address");
driver.findElement(By.xpath("//*[@name='subjectbox']")).sendKeys("My Mail");
System.out.println("Entered Subject of the email");
driver.findElement(By.xpath("//*[@role='button' and .='Send']")).click();
System.out.println("Clicked on send button");
clickSetting(driver);
}
public static void clickSetting(WebDriver driver){
//Tried with Coordinates (doesn't work)
Point point = driver.findElement(By.xpath("//div[@class='G-Ni J-J5-Ji'] [@gh ='s']/*[1]")).getLocation();
System.out.println(point.x + "-" + point.y);
Actions builder = new Actions(driver);
builder.moveByOffset(point.x, point.y).click().build().perform(); //Getting Error.
//Tried with Action Class (doesn't work)
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement SettingWheel=driver.findElement(By.xpath("//*[@data-tooltip='Settings' and @role='button']"));
WebElement SettingsLink=driver.findElement(By.xpath("//*[@role='menuitem']/div[.='Settings']"));
wait.until(ExpectedConditions.elementToBeClickable(SettingWheel));
Actions actions = new Actions(driver);
actions.moveToElement(SettingWheel).moveToElement(SettingsLink).click().build().perform();//Getting Error.
Thread.sleep(2000);
System.out.println("Clicked On Setting");
}
錯誤消息: - 「元素當前不可見,因此可能無法與之交互(警告:服務器未提供任何信息棧跟蹤)」
在此先感謝。
前往另一個網站。遠離谷歌 – Saifur
我沒有選擇在其他網站嘗試它。我只需要在Gmail中執行此操作。請幫助我。 –