2

So I've been working learning how to use Selenium in C# to do some automated testing for a project. However, I've hit a roadblock on this one. I have been trying to figure out of way to click the following link on this webpage.

Here is what I'm trying to target:

<A class='PortalLink' HREF="https://mywebsite.com/myprograms/launchprogram.jsp?" onClick="setUser('login','password');"><span>MyProgram</span></A>

Searching by ClassName hasn't turned up anything. Although there are multiples, I just wanted to see if I could detect the presence of them.

By.ClassName("PortalLink")

I tried a href based search using CssSelector, but this failed as well.

By.CssSelector("[href*='https://mywebsite.com/myprograms/launchprogram.jsp?']")

Lastly, I tried to use XPath and search by class and span content, but this failed to find the link as well.

By.XPath("//A[contains(@class,'PortalLink') and span[text()='MyProgram']]")))

The webpage in question contains 2 frames which I've tried both.

I'm waiting 200 seconds before timing out. What am I doing incorrectly? Thanks in advance for any help!

6
  • FindElements(By.ClassName("PortaLink")) should return an IEnumerable<IWebElement> with all instances of that class on the page. After that you can iterate over them using some other property to elect the one you want. If that's not working for you then the problem is most likely somewhere else (like the page hasn't loaded, or your automation isn't actually looking at the page/parent element you think it is). Commented Sep 12, 2013 at 20:44
  • @evanmcdonnal: Yes, I wrote each of them to the Console using a foreach loop - but there was never any thing inside the collection. Commented Sep 12, 2013 at 21:23
  • Well start looking elsewhere because there is most likely something else wrong. Step through code, be extremely diligent about checking values that could influence the return value of FindElements. Commented Sep 12, 2013 at 21:28
  • You said there are frames in the page. Are you switching to them? Commented Sep 12, 2013 at 21:48
  • @Arran: I explicitly switched to both during my testing. Commented Sep 12, 2013 at 22:46

2 Answers 2

2

Assuming that this element is not appended to the DOM during ajax, your statement should be

By.CssSelector("a.PortalLink[href*='launchprogram.jsp']")

If there are multiple of these links, then we'll need to go further up in the parent-child hierarchy since this link has no more attributes that make this link unique.

Sign up to request clarification or add additional context in comments.

Comments

0

If you can post the parent html of this link then we can suggest more options,

Can you try these......

 //span[contains(text(),'MyProgram']
//span[contains(text(),'MyProgram']/../

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.