how to locate link having href as java script function in selenium using java lang

how to verify link in selenium webdriver
how to find broken links using selenium webdriver
how to click all links on a page using selenium webdriver
how to get all links from a web page using selenium webdriver java
how to handle broken links in selenium webdriver learn automation
how to click a link in selenium webdriver
how to find broken links using selenium webdriver python
how to find broken links using selenium webdriver c#

need to locate libraries and color colorway

hello , I am new to selenium. please suggest how to locate links highlighted in image using selenium. I have tried linktext() but not it is not working.

This is the HTML :

<DIV class=BlueBox><DIV class=BlueBoxHeader><IMG width=4 height=4 src="/Windchill/rfa/images/blue_topleft.gif"></DIV> <DIV class=BoxContent><!-- Start Title --> <DIV style="OVERFLOW: hidden"> <TABLE width="90%" cellSpacing=0 cellPadding=0> <TBODY> <TR> <TD class=BlueHeader style="PADDING-LEFT: 10px"><A href="javascript:toggleExpandableDiv('librariesContent', 'librariesContentIcon');"><SPAN style="PADDING-RIGHT: 4px"><IMG id=librariesContentIcon src="/Windchill/netmarkets/images/expand_tree.png" border=0 valign="bottom"></SPAN>Libraries</A> </TD></TR >

thanks!


linkText works for text between the anchor tags.

I can see partial linkText which is Libraries

code :

driver.findElement(By.partialLinkText("Libraries")).click();  

UPDATE 1 :

You can try this xpath also :

//a[contains(@href,'javascript:toggleExpandableDiv(')]  

code would be :

driver.findElement(By.xpath("//a[contains(@href,'javascript:toggleExpandableDiv(')]")).click();  

UPDATE 2 :

As OP has mentioned that there is a frameset available and desired element is present in that.

You will have to switch the focus of your driver to interact with your desired element.for that you can use this code :

driver().switchTo().frame(driver().findElement(By.name("sidebarframe"))); 
driver.findElement(By.partialLinkText("Libraries")).click(); 

Selenium Click Link By href Value, In Selenium WebDriver, there are a number of ways we can interact QA · Automation · Selenium · API Testing · Java · Python · Agile We can also click links by linkText or partialLinkText . the above function will always click the first link containing the word profile. 2020 DevQA.io About Contact Privacy. How to get page source as it is in browser using selenium. 1 day ago How to capture the status change of a process in selenium, after the process is kickstarted(Run) 4 days ago Exception in thread "main" java.lang.IllegalStateException 5 days ago


Try this,

//td[@class='BlueHeader']//a

How to Find All/Broken links using Selenium Webdriver, Broken links are links or URLs that are not reachable. There are different HTTP status codes which are having different An Automation script using Selenium that will automate the process is a package automationPractice; import java.io. getAttribute("href"); System.out.println(url); if(url == null || url. How to Execute Java Script Using Selenium? Execute the Java Script’s selenium Webdriver given an interface “JavascriptExecutor,” which has two methods. That is: Object executeScript(String arg0, Object arg1); Object executeAsyncScript(String arg0, Object arg1); By using two methods in our automation script, we can able to execute the Java Script’s.


You can use Xpath :

//a[normalize-space()='Libraries']

Execute JavaScript with JavascriptExecutor, http://www.swtestacademy.com/selenium-tutorial-java-junit/ How to handle javascript alerts with javascriptexecutor in selenium: In Console tab, you can call JavaScript functions and see their //Ref1: https://seleniumhq.github.io/​selenium/docs/api/java/org/ I suggest you to check below two links. How to execute JavaScript in Selenium WebDriver. Below code snippet shows you how to execute a JavaScript in Selenium WebDriver. 1. WebDriver Example. In this example, it uses WebDriver to load “google.com”, and executes a simple alert () later.


You can use this xpath selector for selecting these three highlighted elements :

"//a[contains(.,'Libraries')] | //a[contains(.,'Calendar')] | //a[contains(.,'Color')]"

It will give a list of 3 elements

It will work for you. Please do let me know if any issue occurs.

The logic is that you have to use "OR" condition if you want to get these elements.

Check for iframe existence as suggested by other answers and than try to get elements using this selector

Unable to click on html link using Selenium WebDriver, In my code, Anchor tag is having the href attribute as below "javascript:void(0). but when we click on anchor tag form was submitting though  please provide the stack trace and html code snippet of the link (and its parent container). Normally the code you are using should work. – Prashant Shukla Aug 23 '12 at 11:17. updated above wíth the entries stripped down to the menu element.


JavaScript DOM: Collect the value of href, hreflang, rel, target, and , Icon Angular React Vue Jest Mocha NPM Yarn Back End PHP Python Java Node.js Ruby C programming PHP Composer Laravel PHPUnit ASP. JavaScript DOM: Exercise-4 with Solution. Write a JavaScript function to get the value of the href, hreflang, rel, target, and type attributes of the specified link. Simulates keystroke events on the specified element, as though you typed the value key-by-key. This is a convenience method for calling keyDown, keyUp, keyPress for every character in the specified string; this is useful for dynamic UI widgets (like auto-completing combo boxes) that require explicit key events.


Complete Guide For Using XPath In Selenium With Examples , Locating dynamic elements have always been the pain area while you Writing Dynamic XPath in Selenium by different ways: and <a target="_blank" href="​https://www.lambdatest.com/privacy">Privacy current node with tagname input having attribute as name with value import java.util.concurrent. What is jQuery and how to use it, how to run jQuery code in Selenium WebDriver are explained in this post. What is jQuery: jQuery is just a Java Script Library, it simplifies the task with less code.


innerText, Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java  Simulates keystroke events on the specified element, as though you typed the value key-by-key. This is a convenience method for calling keyDown, keyUp, keyPress for every character in the specified string; this is useful for dynamic UI widgets (like auto-completing combo boxes) that require explicit key events.