Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Friday, May 27, 2016

Action class works in debug mode in selenium webdriver

Action class works in debug mode in selenium webdriver


I have written the code and that works well when I run this is debugging mode but when I run it in normal mode then I am getting the following exception

     org.openqa.selenium.NoSuchElementException: no such element:        Unable to locate element: {"method":"xpath","selector":".//*[@id='address-0']/span"}  

The code I have written is:

    WebElement searchBox  = driver.findElement(By.id("search-input"));      searchBox.sendKeys("somepostcode");      Actions actions = new Actions(driver);      actions.moveToElement(searchBox);      WebElement address = driver.findElement(By.xpath(".//*[@id='address-0']/span"));      actions.moveToElement(address);      actions.click();      actions.perform();  

I am not able to understand where should I put wait.

I am using eclipse IDE. The functionality works like when I put some postcode in the search box it search for some addresses at runtime and the user has to select any address related to the postcode. Ajax has been used to fetch the postcode

Here search box is a textbox.

Please let me know if more information is required.

Answer by Ranjith's for Action class works in debug mode in selenium webdriver


Try adding some wait time before WebElement address = driver.findElement(By.xpath(".//*[@id='address-0']/span"));

Answer by abhijeet kanade for Action class works in debug mode in selenium webdriver


Error tells you that, you are trying to create an instance of WebElement "address" before its visible on the page. Try adding wait before WebElement address = driver.findElement(By.xpath(".//*[@id='address-0']/span"));

Answer by Eugene S for Action class works in debug mode in selenium webdriver


In cases like this, when the script works in debug mode but fails during normal it is almost always the issue with timing. So your page is just not fully loaded at the time you are trying to locate that element.

Place an explicit wait just before your problematic element. It's usually not the best practice to use explicit wait but you can do it as a quick try to see if that solves your problem. If that does you can refactor it into a sturdier solution later.

WebElement myDynamicElement = (new WebDriverWait(driver, 10))  

Answer by Kishan Patel for Action class works in debug mode in selenium webdriver


Hope this will help you..

    WebElement searchBox  = driver.findElement(By.id("search-input"));        searchBox.sendKeys("somepostcode");        Actions actions = new Actions(driver);        actions.moveToElement(searchBox);        WebDriverWait wait = new WebDriverWait(driver, 20);        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='address-0']/span")));        WebElement address = driver.findElement(By.xpath(".//*[@id='address-0']/span"));        actions.moveToElement(address);        actions.click();        actions.perform();  

Answer by user965884 for Action class works in debug mode in selenium webdriver


I have solved this problem by breaking the postcode in two parts

searchBox.sendKeys("postcodePart1");  searchBox.sendKeys("postcodePart2");  

There must be kind of on change event was calling.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.