1

I have tried a lot to find a solution to a link that has onclick attribute but I could noot find a clue The HTML for the element like that

<a href="javascript:void(0);" onclick="dealSideLinkPage('/lawyerViews/lawOrders/newCase.jsp')">أمر أداء جديد</a>

I tried to use ExecuteScript but got error. I am using selenium in VBA Trying this line doesn't work with me

.ExecuteScript "document.getElementByXPath(""//*[@id='SrvTabs1']/div/div/div[1]/nav/div/ul/li[3]/a"").click()"

2 Answers 2

3

You can try any of these XPaths -

//a[text()='أمر أداء جديد']

//a[contains(text(),'أمر أداء جديد')]

Note: Onclick and style attributes are not suggested to write XPath.

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

Comments

1

To click() on the element with text as أمر أداء جديد using the onclick attribute you can use either of the following Locator Strategies:

  • Using FindElementByLinkText:

    driver.FindElementByLinkText("أمر أداء جديد").click
    
  • Using FindElementByCss:

    driver.FindElementByCss("a[onclick^='dealSideLinkPage'][onclick*='newCase']").click
    
  • Using FindElementByXPath:

    driver.FindElementByXPath("//a[starts-with(@onclick, 'dealSideLinkPage') and text()='أمر أداء جديد']").click
    

7 Comments

I think the problem is related to the position of the element. For the first time in loop, it works well with no problem but in the second loop, the problem occurs element click intercepted. so how can I get to the top of the web page each time at the start of the loop?
@YasserKhalil Add some wait and retest please.
No the problem is not in the wait I am sure. When I go manually to the top of the webpage, the line works very well. I have tested that myself more than once.
How about implementing ScrollIntoViewCenter()
I have found a better way which uses ExecuteScript too and this solved the problem .ExecuteScript "arguments[0].click();", .FindElementByXPath("//a[starts-with(@onclick, 'dealSideLinkPage') and text()='أمر أداء جديد']"). Thank you very much for the great support.
|

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.