我正在使用Java Eclipse練習Selenium。我希望能夠使用Selenium登錄到Twitter。雖然我沒有看到任何與用戶名和密碼字段相關聯的元素。爲什麼沒有元素?我怎樣才能訪問這些領域?如何找到元素[For Selenium]
謝謝!
我正在使用Java Eclipse練習Selenium。我希望能夠使用Selenium登錄到Twitter。雖然我沒有看到任何與用戶名和密碼字段相關聯的元素。爲什麼沒有元素?我怎樣才能訪問這些領域?如何找到元素[For Selenium]
謝謝!
你可以像下面那樣使用xpath。這些表達式正在工作。
WebDriver driver = new FirefoxDriver();
driver.get("https://twitter.com/login");
driver.findElement(By.xpath("//div[@class='signin-wrapper']//input[@name='session[username_or_email]']")).sendKeys("Yourusername");
driver.findElement(By.xpath("//div[@class='signin-wrapper']//input[@name='session[password]']")).sendKeys("YourPassword");
driver.findElement(By.xpath("//button[contains(text(), 'Log in')]")).click();
非常感謝!這真的很有用@Maninder! –
請使用如下的的XPath。我們可以訪問它。
(// * [@名稱= '會議[username_or_email]'])[2]
謝謝Ramesh!感謝你的幫助! –
你測試了這個嗎?它會工作Girri –
你可以簡單地訪問這些領域與XPath
:
//input[@placeholder="Phone, email or username"]
//input[@placeholder="Password"]
讓我知道,如果出於某種原因你不能使用這些選擇器或發生任何例外情況
謝謝安德森!感謝你的幫助! –
可能的重複[如何在java的selenium webdriver中通過索引查找元素](http://stackoverflow.com/questions/27208872/how-to-find-an-element-by -index-in-selenium-webdriver-for-java) – Pushkraj
「class」和「name」屬性有什麼問題? – Guy