I'm writing a test when you get all the links from the website and click them. But I need to click some links that in the beginning are hidden or some links that appear only in other pages. Till now, I'm only got to the point that test gets all the active links from homepage and clicks them. I'm new to Selenium webdriver and java, so can you suggest how should I write the test that checks for new appearing links after clicking one or something similar?
I usually write my Selenium tests much more specifically, but were I to attempt this I suspect I would start by making use of findElements(By.tagName("a")) to get all currently available anchors, probably put them into a data object which included if that anchor as been clicked yet and put those data objects into a Set. Map that Set to the currentUrl to keep track of what links were found on what pages. After a click (and recording that you clicked that anchor in its data object) you could check the currentUrl (without any #s) with the last one (without any #s) to determine if that click loaded a new page. If the urls match, I would call findElements again and add those to the existing Set. If they don't match repeat the process for the new currentUrl. Some additional things to be aware of would be handling new Windows and frames, which would require a switchTo and iterating through all the frames (and nested frames).
Related
I am working on one selenium project. My scenario is, I have multiple forms one after another. After filling them I have to click on the Next button. I have 4 pages with the next button and they have the same XPath. When I try to use the same web element for the next button it works once but when I try to use that same thing again on a different page It shows element intreactable error.
I would try the following to identify why you get the interactable error (it would help to give us the error at least as is found on the Selenium Documentation)
try to click using javascript executor,
try to add webelements for each action you need to perform (so 4 webelements for each 'Next' button). If it works in this way maybe the webelement is not refreshed after you use it (maybe is a static field). Try also to work with Page Factory pattern.
If nothing works, we should receive more information to be able to help.
I am a beginner in Selenium Automation, and stuck with a situation, where, if I open a page xyz.com, and login, then there are some text box and dropdown and buttons to be clicked but the thing is, after the driver get to that page, I can see those elements, and can get the ID and necessary tags, but these whole page consist of 3 different (.do) page.
For example:
1. main page is abc.do
2. left panel is mno.do
3. center is xyz.do
Image of Inspect Element in IE
and my elements exists in xyz.do, and links in mno.do.
I am using eclipse to code, Selenium 3.1, IE 11
How can I switch between them so that my driver can find the elements, write now its showing element cannot be found, and when I pulled the source code its providing of only first .do page.
Please help.
Thanks.
It seems the page is using frames or iframes, but because you do not provide a URL, it's only a guess.
So, to switch a frame/iframe, simply use the switchTo method:
driver.switchTo().frame0); // Frame by number
driver.switchTo().frame("iframe1"); // Frame by selector
After that call, you switch into the "context" of that page/frame/iframe.
I am using Selenium Chromedriver (Java) to navigate around a webpage. I need to send a Tab key many times (50+) to explore the entire webpage. However I cannot determine which element to send the Tab key to, so I keep getting WebDriverException: element not interactable errors.
Is there some way to determine which element is handling the Tab? I have tried many different HTML elements on the page but could find the correct one.
Thanks!
one more option is using action class.Just keep this statements in loop as per your need.
Actions action = new Actions(driver);
action.sendKeys(Keys.TAB).build().perform();
Recently I have been tasked with Automating MS CRM 365 with Selenium Automation. I have opted for Using Gradle and Java for this, using IntelliJ.
Currently my issue is when I am on a form page, I am unable to access any elements on that page for data entry or drop-down selection.
I have tried using iFrame switching:
driver.switchTo().frame(driver.findElement(By.cssSelector("#contentIFrame0")));
I have tried selecting from ID, from XPATH & from CSS.
The code is a simple driver.findElement; there isn't anything special about it. I seem to be failing at the most basic part.
driver.findElement(By.id("firstname_i")).click();
Expected outcome: To be able to access the element and process a Click, followed by either a selection from drop-down or a text entry.
Actual outcome:
org.openqa.selenium.NoSuchElementException: Unable to find element with css selector == #firstname_i
Image to Firefox Inspection of the Element
I was wondering if there is something in the CSS that's stopping me from accessing the element. I noticed that the element for the 'text' box is under a few layers and is not displayed, unless the top layer is accessed. However I cannot event find that element to follow the flow. Hope that makes some sense.
So after a bit of playing about, I noticed that my iframe switch was working however the element I was trying to access was correct just not complete, not sure if this is ever relevant to anyone else but I had to add a method to counter my element issue by select the initial element "name" and then selecting a second element as the input "name_i".
Where as if I tried to select "name_i" initially I get the whole "element not found" as the CSS sets it to invisible unless activated by mouse over/ click on the first element (overlay?).
This seems to be the case across the whole form page.
Never worked with MS 365 before so I have no idea if this is viable or even common.
Thanks.
How to verify if Tab on Web Page is selected using Selenium RC
I wanted to one very simple thing. Does anyone know using selenium RC Python Client how I can know if a Tab is selected on web page?
By tab I mean the following examples from the following link-
http://esdi.excelsystems.com/wsexmp/DIVTAB.pgm?wsnum=00096
I have used focus(), isSomethingSelected(), isVisible() but didn't get the solution.
I need to verify that the specific tab is selected by default after webpage opens. Isn't there a method like is_tab_selected(tab_locator)??
please provide the clear solution pls..
I have used focus(), isSomethingSelected(), isVisible() but didn't get
the solution.
These methods use the common HTML element terminology.
focus() is for elements that are focused, meant as when you click a focusable element, it has a focus on it. To see what I mean, you can loop through the focusable elements on your page via pressing the Tab key repeatedly. This changes focus.
is_something_selected() is for selecatble <option> elements (which are the children of a <select> element)
is_visible() tells you whether an element is actually visible on the page or whether it is hidden via CSS.
Anyway, there's no is_tab_selected(tab_locator) method, because there's no such thing as a tab. In your case, your "tabs" are just simple clickable <a> elements which have a class attribute tab-active or tab-disabled based on their state.
Therefore, if you wanted, for example, to know whether the second tab is active, you would do
is_element_present("css=#tab2.tab-active")
This will return either true or false based on whether the tab is selected or not.
Or the other way around, if you wanted to know which tab is currently active, you would do:
get_attribute("css=.tab-active#id")
This will return the id of the selected tab.
You have to find a unique tag in your webpage. You can do
driver.findElement(By.xpath(".//tagname"))
If the above line doesn't throw any exception, you can confirm that you are located in your webpage.