last day (14 days later) » 

2:46 PM
1
A: Looping through multiple moveToElement in selenium/webdriver c#

SaifurInstead of hard coded index number you should find the target elements with FindElements then loop though and click back and forth. Second think, you need to use proper wait time to make sure the elements are loaded properly. Third, Need to find the element on the fly cannot simply iterate throu...

 
@Subh You may have noticed every time I come to the page then find the collection of elements and then click on ith element. There is no reason for StaleElementReference exception would happen because of DOM refresh. What makes you think like that though and, yes, I tested this!
 
The first problem I'm having is that although I'm running .NET version 4.5, IReadOnlyCollection<T> is not being found in System.Collections.Generic; Also, none of the other data structures I've tried will allow me to impicitly set the collection to type Driver.FindElement(xPath); @Saifur
 
You can simply use var and that's FindElements not FindElement I guess is a typo.
 
Yes, that was a typo on my part. In what context can I replace the Collection with var? @Saifur
 
Yes like var linkCollection = Driver.FindElements(xPath);
And IReadOnlyCollection<T> Interface is present in .NET 4.5 see this. It's member of System.Collections.Generic namespace .You have to import using System.Collections.Generic; reference
 
2:46 PM
Yes, this is the frustrating part. The import is present, but Visual Studio continues to say that The type or namespace 'IReadOnlyCollection' could not be found (are you missing a using directive or an assembly reference?) I replaced the collection with var and the test passed - but it clearly did not click through all of the links. @Saifur
 
Hey man
So ya may be getting some other issues because cnn a very dynamic page
I can go revisit the test and verify the test works if you want and give me the stacktrace
 
the stacktrace isn't providing me with anything
 
what's the issue thoug?
 
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
A first chance exception of type 'Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException' occurred in Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
 
well just to clearify I wrote a selector to grab the link from The latest paenl which is about only 8 link right now
 
3:12 PM
what browser are you using?
 
for my selenium testing (since it's the easiest) i'm using firefox
 
I cannot reproduce the issue on my end dont really know what's going on.
I ran the same test on ff
 
using var or using the IReadOnlyCollection?
since i'm getting an out of range exception, I believe that my issue is there (using var instead of the collection)
 
using both
they both work for me
and they should
Can you give me the whole code block including the namespaces so that I can troubleshoot your code
if possible
?
 
sure
using System;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Support.UI;

public static bool TestFindAssets()
{
bool result = false;
Actions action = new Actions(driver);
var findAssetsClick = driver.FindElement(By.XPath("/html/body/div/header/nav/ul/li[3]/a"));
var home = driver.FindElement(By.LinkText("Home"));
By xpath = By.XPath("/html/body/div/header/nav/ul/li[3]/ul/li[1]/a");
 
3:30 PM
Keep that in mind this is very important to know how you write the selector. Because that's the key here
Is it a public site you use?
 
no, its a company site that I'm automating tests for.
 
I am afraid your selector worries me.
 
yeah, i'm not fond of it either.
 
it's not probably written correctly to return all the links you may need
 
if you notice in one of the commented out lines, the xpath presents an opportunity to iterate through it. "/html/body/div/header/nav/ul/li[3]/ul/li[1]/ul/li[" + i + "]/a"
so i'm trying to work with this since it's the most straight forward place to go from in terms of the convoluted xpaths
 
4:04 PM
look at this to see what I mean. You have to write a selector to grab all the links you want
 
4:37 PM
Ah. I think the problem I see now that i'm looking at your screenshot is that the links i'm trying to grab are only displayed in a javascript type mouseover drop down which is why I was using the action.MoveToElement() method
 
Yes until the dom is exposed you wont get the correct collection
 
(I know it doesn't) but one would think that simply waiting until the element exists to click would fix that issue.
 
sorry could not help you more since I don't know much about your source code
but you need to expose the dom by clicking or somethig(probably action) to make the elements exist
then grab the collection
 
I'll try that
 

last day (14 days later) »