我有一種情況 - 當我點擊我的測試URL(http://example.com)按鈕(ABCB),它會當我點擊被重定向到不同的URL(http://yourname.xyz),並有一個按鈕(xyzB),它會回到我通常的測試網址(http://example.com),並執行進一步的功能。請讓我知道我該如何做這個Selenium Webdriver。硒的webdriver - 最好的處理方法重定向的URL
-4
A
回答
0
這是一個簡單而直接的任務。我寫了一些僞代碼,因爲你沒有分享任何html代碼供參考。請使用下面的代碼並嘗試。
driver.findElement(By.Xpath("<your xpath reference of button in first page>").click(); //to click on the button, and will navigate to target page
driver.getTitle();// to get the title to ensure you are in the correct page
driver.findElement(By.Xpath("<your xpath reference of button in second page>").click();
driver.getTitle();// to get the title to ensure that the browser is navigated back
+0
好的,謝謝。由於url會改變,我認爲我們需要以不同的方式處理它。 –
0
如果我的理解沒有錯,你的情況是這樣的
driver.findElement(By.Xpath("Your xpath").click();
//wait for few second for loading site
for (String windows : wd.getWindowHandles()) {
wd.switchTo().window(windows);
if (wd.getCurrentUrl().startsWith(Link + "xyz.com")) {
//Your Operation
}
if (wd.getCurrentUrl().startsWith(Link+"yzx.com")) {
//Your Operation
}
}
在這裏,我所做的一切,我點擊重定向link.And等待站點load.After重定向幾秒鐘,我渴望迴歸標籤鏈接開始,在那裏你可以給其他條件也!
希望它會幫助你
0
先點擊第二URL定位匹配的標題,回來第一個URL在這裏做同樣的事情,通過這個,你可以處理重定向URL
你可以試試這個示例
WebDriver driver=new FirefoxDriver();
//Go to first URL and click on Download menu
driver.get("http://www.seleniumhq.org");
driver.findElement(By.xpath("//*[@id='menu_download']")).click();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
//Click on the Source code to redirect to second URL
WebElement sourceCode=driver.findElement(By.xpath(".//*[@id='mainContent']/p[1]/a[2]"));
sourceCode.click();
//Get the title of SecondURL and match
String SecondUrl= driver.getTitle();
if(SecondUrl.contains("GitHub - SeleniumHQ/selenium: A browser automation framework and ecosystem."))
{
System.out.println("welcome to second URL");
}
//come back to First URL by click on link
driver.findElement(By.xpath("//a[contains(text(),'http://seleniumhq.org')]")).click();
//Get the title of FirstURL and match
String FirstUrl= driver.getTitle();;
if(FirstUrl.contains("Selenium - Web Browser Automation"))
{
System.out.println("welcome to First URL");
}
相關問題
- 1. 最好的處理方法
- 2. 最好的重定向方法?
- 3. 硒的webdriver:處理DROPDOWNS
- 4. 硒的webdriver自動重定向
- 5. nginx的反向代理最好的方式來重定向
- 6. 最好的辦法重定向錯誤的URL的
- 7. 的元模糊處理URL重定向
- 8. 友好的URL重定向
- 9. 在硒webdriver處理重複ID
- 10. 最好的方法來處理NSString Memeory
- 11. 最好的方法來處理OOME android
- 12. Liferay的友好的URL重定向到控制器的方法
- 13. 最好的重定向方式
- 14. 的Windows在處理硒webdriver的用java
- 15. 意外的事件處理的webdriver /硒
- 16. 有沒有更好的方式來處理cookie /重定向
- 17. 硒的webdriver處理窗口彈出
- 18. 如何處理使用硒webdriver的ModalDialog?
- 19. 如何處理org.openqa.selenium.UnhandledAlertException硒的webdriver
- 20. 什麼是在IIS中處理數千個URL重定向的最佳方式
- 21. 管理重定向的最佳方式
- 22. URL重定向方法
- 23. 最好的方法來處理方向變化的多個可交換片段
- 24. 最好的方法來備份用戶的輸入處理方向變化
- 25. 處理輸出重定向的最佳方式是什麼?
- 26. 將HTTP重定向到HTTPS。什麼是最好的方法?
- 27. 使用.htaccess進行HTTPS重定向的方法最好?
- 28. 無法處理蟒蛇瓶重定向()「POST」的方法
- 29. 更好的方法來處理方向更改時的活動重啓?
- 30. 內聯處理url重定向
向我們展示您的代碼。 –
你在哪裏遇到錯誤/問題?錯誤堆棧跟蹤? – DebanjanB