How do I find this element in Selenium (button on page to press)?
-
I am trying to press the "grid" class button that is on a web page but I am having trouble. Here is the HTML: <li id="prodlist" class="prodtab"> <span> Products</span> <div class="grid" onclick="goToView('productGrid');"></div> <div class="list" onclick="goToView('productList')"></div> </li> Here is what I tried but it gives org.openqa.selenium.NoSuchElementException: driver.findElement(By.xpath("div[contains(@class, 'grid')]")).click();
-
Answer:
The solution to this kind of problems is usually either switch to an iframe, if the element is inside it: WebElement frame = driver.findElement(by.cssSelector("iframe.ajaxStoreNumberAppendSrc")); driver.switchTo().frame(frame); // then, search for element driver.findElement(By.xpath("//div[contains(@class, 'grid')]")).click(); Or, make an explicit wait to wait for element to become present: WebDriverWait wait = new WebDriverWait(webDriver, 5); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[contains(@class, 'grid')]")));
Claude Bastien at Stack Overflow Visit the source
Related Q & A:
- How can I remove an element in a repeated list?Best solution by Stack Overflow
- How can I find who has visited my page in yahoo 360?Best solution by Yahoo! Answers
- Where do I find my pop up blocker button?Best solution by Yahoo! Answers
- How do i find someones web page by their email address?Best solution by Yahoo! Answers
- How do I find favorites tab on new yahoo page?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.