Can someone help me with extracting the text Effective Date from the image provided below? What would be the correct way to create an xpath for this?
Below is the snapshot of the HTML:
Can someone help me with extracting the text Effective Date from the image provided below? What would be the correct way to create an xpath for this?
Below is the snapshot of the HTML:
There is a possibility, but I recommend using CSS for this task.
If you choose XPath:
String text = driver.findElement(By.xpath(
"//*[@class='targetDiv']/.//span[contains(@id,'specificLabel')]"))
.getAttribute("innerHTML");
If you prefer CSS:
String text = driver.findElement(By.cssSelector("#DivId span.desiredLabel"))
.getAttribute("innerHTML");
When working with Selenium, my preferred locator is typically the element's id
. However, in this particular situation, the target element does not have an id attribute. In such cases, I would look for the name
property as an alternative, but unfortunately, it is also not present. As a last resort, I turn to using xpath
, even though it may be slower. Nevertheless, xpath
is versatile and can locate almost any element. In your scenario, the following xpath locator could be used:
String elementLocator = "//span[@id='rightmandatory']/parent::th";
String text = driver.findElement(By.xpath(elementLocator)).getText();
If the getText()
method retrieves the text from the span element, you can consider using
.getAttribute("innerHTML")
as an alternative. While there are other locators available, you specifically asked for the xpath option. I hope this information proves helpful.
The Effective Date text is embedded in a text node. To extract this text, you will need to employ the use of WebDriverWait for the method visibilityOfElementLocated()
and you can opt for either of these Locator Strategies:
cssSelector
:
System.out.println(((JavascriptExecutor)driver).executeScript("return arguments[0].lastChild.textContent;", new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("table.data_form.label tbody > tr > th")))).toString());
xpath
:
System.out.println(((JavascriptExecutor)driver).executeScript("return arguments[0].lastChild.textContent;", new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//table[@class='data_form label']//tbody/tr/th")))).toString());
I am having trouble with my ajax request to retrieve data from node.js. The interaction between the two seems off, but I can't pinpoint where the issue lies. Below is the snippet of my ajax get request: $.get('/notificationsNumber', ...
In my search.html file, I have set up a form where users can input their search criteria and click the search button to find information within a database of 1000 records. The HTML part is complete, but I am unsure how to create the action link for the for ...
Today, a question arose while I was at work: What happens when I have numerous users accessing my website concurrently, each with their own data stored in user sessions, and my JVM runs out of memory due to its limitations? Despite searching through the ...
Following the update to the latest version of Node.js, I encountered error messages when attempting to use npm audit fix --force. It appears that resolving dependency tree issues is proving to be difficult. Despite extensive research and trying various s ...
I recently downloaded a theme from this source. I need to specify script and CSS in the index.html file. The body section of index.html looks like this: <body> <app-root></app-root> <script type="text/javascript" src="./assets/js ...
I'm attempting to implement the functionality from this Codepen demo into my project. I've copied over the HTML, CSS, and JavaScript code: <!DOCTYPE HTML> <html> <head> <script> var dialog = docume ...
When making a reservation at a hotel using the CJS Chrome extension, I am attempting to extract information about available rooms and rates both when the page loads and when the user changes dates. My current method involves injecting JavaScript into the p ...
I recently upgraded my browser from chromium version 67 to the latest Chrome version 79. However, I noticed that after the upgrade, the CSS transitions on my website have become very laggy and unresponsive. Surprisingly, everything works perfectly fine on ...
I need to display a static array on a webpage without Angular watching its value. With that requirement in mind, my question is: Which method is faster: using a directive to fetch a scope variable and create an HTML element with this variable as a hard-co ...
I'm currently working on incorporating copy to clipboard functionality into my app using Electron. This is the command I am using: methods: { copyToClipboard () { if (process.env.MODE === 'electron') { this.$q.electro ...
I am looking to modify my code in order to open all clicked links in new browser tabs once the page loads using driver.get "http://www.example.com". Despite receiving answers from previous questions, the solutions provided have not met my expectations. Bel ...
I have a string variable that I need to use in creating a JSON file. The JSON file should contain the content of the variable named "result". Any assistance with this task will be greatly appreciated! Thank you in advance! @TargetApi(Build.VERSION_CODE ...
I have a div tag enclosed within a content tag due to the implementation of a masterpage containing the forms and body tags. <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server"> <div id="xxx" style="overflow:s ...
I've been facing an issue while trying to pass the selected month from a select list in HTML using Ajax. Every time I select a month, it doesn't show up as expected. Initially, there's a placeholder "nothing" displayed due to the if-else con ...
My current approach involves using this code snippet to retrieve data from Twitter through its API: $.ajax({ url : apiUrl, cache : false, crossDomain: true, dataType: "jsonp", success : f ...
I'm interested in learning more about jQuery caching and how it can enhance performance. Can you explain how to properly utilize this technique? From what I understand, when using a jQuery selector, you're essentially searching the DOM to create ...
Currently, I am facing an issue where the elements in viewport trigger the animation twice when the user scrolls. This strange behavior only occurs when the page is loaded at the very top and then scrolled down. If the page is loaded anywhere else, everyth ...
Hi all, I have a challenging issue that I'm struggling with in terms of jQuery/JavaScript. I am fetching data through standard AJAX without using any frameworks like jQuery. Now, the dilemma is that once the page has loaded, I need to implement a jQu ...
In Vue.js, I have developed a 'mini-game' that allows players to 'fight'. After someone 'dies', the game declares the winner and prompts if you want to play again. However, I am facing an issue where resetting the health of bo ...
I have a unique idea for my website - I want to create a special counter that gradually increases to a specific number, but does so over the course of an entire year. Imagine starting at 0 and aiming to reach 35340340 after exactly one year has passed. It ...