问题
I'm learning how to use Selenium Webdriver(RemoteWebDriver) and I'm having some problems with a page I'm training on because I can't click anywhere and I can't locate any element on the webpage.
I think the webpage is developed by using Spring or maybe Ajax and that's why I can't get to click anything.
This is the url: http://tinyurl.com/d9x453
For example, I'm not capable even to press the first button you can see on the webpage, Am I losing something?
Please, I'd really appreciate it If someone could help me.
Regards-
回答1:
I just need to wait for javascript execution. You may do that by checking some control and if it is null set some Thread.sleep(1000);
回答2:
You might need to two different waits here. A. Wait for any script to finish loading B. Wait for your page to finish loading
A. If your App is using jquery it's fairly simple. Taken from here
public void WaitForAjax()
{
while (true) // Handle timeout somewhere
{
var ajaxIsComplete = (bool)(driver as IJavaScriptExecutor).ExecuteScript("return jQuery.active == 0");
if (ajaxIsComplete)
break;
Thread.Sleep(100);
}
}
B. wait for your page to finish loading. Taken from here
IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
use these two before performing any actions. Hope that solves
回答3:
Also Try with selenium.fireEvent("id=search-bottom", "blur").[Note havn't tested the code]
Which browser are you trying?
This is the code I wanted to share :
private WebElement searchButton;
@Test
public void testYourSearchClick(){
final FirefoxDriver ffDriver = XXYOURUtillyClassForDriver.createFirefoxDriver();
try{
ffDriver.get(System.getProperty("selenium.baseURL"));
searchButton= ffDriver.findElement(By.xpath("//fieldset[@id='search-bottom']"));//or your //button class
searchButton.click();
}catch(SeleniumException e){
e.printStackTrace();
}
}
来源:https://stackoverflow.com/questions/25018864/selenium-webdriverremotewebdriver-cant-click-anywhere-on-the-webpage