我正在寫硒驅動程序腳本。腳本的場景是:
1)登錄www.yahoomail.com
2)成功登錄。
3)點擊「撰寫」按鈕
4)在「收件人」字段中輸入電子郵件ID。
5)輸入主題「主題領域。
6)在輸入電子郵件正文 「文本」 字段。
7)點擊 「發送」 按鈕。
如何處理每次動態更改的Xpath?
使用Firepath,我已經採取了上述領域的的XPath 。在「撰寫」頁面 但每次當我打開撰寫頁面時,這種動態的XPath變化
下面是我使用的腳本:
WebDriver oYahoo = new FirefoxDriver();
oYahoo.get("http://www.yahoomail.com/");
oYahoo.manage().window().maximize();
oYahoo.findElement(By.xpath(".//*[@id='login-username']")).sendKeys("[email protected]");
oYahoo.findElement(By.xpath(".//*[@id='login-passwd']")).sendKeys("[email protected]");
oYahoo.findElement(By.xpath(".//*[@id='login-signin']")).click();
oYahoo.findElement(By.xpath(".//*[@id='Compose']/button")).click();
oYahoo.findElement(By.xpath(".//*[@id='yui_3_16_0_1_1448364357109_2222']")).sendKeys("[email protected]");
oYahoo.findElement(By.xpath(".//*[@id='subject-field']")).sendKeys("Hi This is my first automated mail");
oYahoo.findElement(By.xpath(".//*[@id='yui_3_16_0_1_1448364357109_1966']")).sendKeys("Hi This is my first automated mail");
oYahoo.findElement(By.xpath(".//*[@id='yui_3_16_0_1_1448364357109_2465']")).click();
oYahoo.quit();
我們可以這樣做它會動態地使用Xpath?我們是否需要在某些課堂上繪製這些東西?我們是否必須爲「撰寫」彈出窗口編寫任何其他類? 如果「是」,那我們該怎麼做呢?
這是自動化的基本問題。我建議你做一些事情,比如找到像「yui_ *」這樣的id的「第一個」元素。或者找到一個你可以找到其子的基本元素。 – DMart