Selenium Webscraping - Print element that is not visible on the site but its on Inspect - selenium

enter image description here
I'm trying to print this 91040 from the site but I can't seem to do it and I think the reason is that 91040 is not visible on the site but only on inspect.
element = driver.find_element(By.XPATH,'//div[#class="code-container"]//span[2]')
When I paste this XPATH in the find bar on Inspect it locates the item but when I'm trying to print the element nothing gets printed. I tried these options.
print(element)
print(element.text)
So I'm thinking that the problem is that 91040 is not an actual visible text.

For anyone having the same problem I found the answer
hidden_text = element.get_attribute("textContent")

Related

VBA selenium scroll windows to element point

In VBA I need to move in Selenium viewport to the element to be clickable. I tried code below ;
.Mouse.MoveTo(.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a"),13,13) 'error Expeted = sign
.Actions.MoveToElement (.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a")) 'ineffective screen does not scroll down. Note: Windos is set to Maximize
the code is added but does not work, I could not add to the comment section
.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a").Click
.Actions.MoveToElement(.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a")).Perform
.Actions.MoveToElement(.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a")).Perform
.Actions.MoveByOffset(300, 300).Perform
.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a").Click
To move Selenium's focus to the element you can use either of the following lines of code:
.Actions.MoveToElement(.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a")).Perform
or
.Actions.MoveToElement(.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a"), 13, 13).Perform

Is there a way to click on anchor link

Please help me as the anchor tag looks like the below
<a title ="excel" class="activelink"style="Text-Decoration: none; onclick="$find('ReportViewerControl').exportReport('Excelopenxml');" href ="javascript:void(0)" alt="Excel" _selected="true"> Excel</a>
This doesn't have any document id or class.. Any help would be highly appreciated.
I try to check your HTML code and found that it contains the class but it can be possible that many other elements on the page using the same class. If you try to access the link using that class then it can possible that you click the incorrect element on the page.
We can see that the link contains the ' Excel' text. We can try to loop through all the links on the page and try to match the innerHTML to find that specific link.
Example:
'Below is code to loop through anchor tags, find the specific link, and click it.
Set elems = IE.document.getElementsByTagName("a")
For Each elem In elems
If (elem.innerHTML) = " Excel" Then
elem.Click
Exit For
End If
Next elem
Output:
In a similar way, you can also match other attributes from the anchor tag that may also help to click the link.
Note: This code example is for clicking the specific link on a page. It may not help you to automate the file download.
Further, you can try to modify the code example as per your own requirements.

selenium send key for xpath not working

I want make automation for this web site
in this web site 3 text box are here check image
1st text box x path is /html[1]/body[1]/div[3]/div[1]/div[2]/div[1]/searchbar[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[1]/input[1]
here is my code
driver.findElement(By.xpath("/html[1]/body[1]/div[3]/div[1]/div[2]/div[1]/searchbar[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[1]/input[1]")).sendKeys("rio salon");
when I run this code I got this error
Exception in thread "main"
org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard
How can i fix it? I hope my xpath is correct.
The field has aria-hidden=true attribute, so you get ElementNotInteractableException. You need to click on the dropdown first to change the attribute to true
WebElement dropdown = driver.findElement(By.xpath("//*[#id='search-form']/div/div[1]/div/div[1]/span"));
dropdown.click();
WebElement textField = dropdown.findElement(By.xpath("./parent::div/following-sibling::input[contains(#class, 'ui-select-search')]"));
textField.sendKeys("rio salon");
You can click in an input field with a div or span tag, but you cannot type in the field. So, your XPath must be written with an input tag if you want to sendkeys or type in an input field. For example:
//input[contains(#placeholder,'Site')]

Tosca: How to scan Dropdown textbox which disapper upon opening xScan

I have a problem in scanning a drop-down menu which disappears upon opening the xScan. I need to get the module id of the dropdown menu to verify some test steps.
Do you have any solution with this if it is not really possible to get the module id of the dropdown menu?
Open developer tools in your browser of choice (F12), navigate to the console and input the following code:
var fulldoc='';
var scrollX=0;
var scrollY=0;
document.addEventListener("keydown",function(event){
if(event.key=='q' && event.altKey){
fulldoc=document.body.outerHTML;
scrollY=window.pageYOffset;
scrollX=window.pageXOffset;
}
if(event.key=='w' && event.altKey){
document.body.outerHTML=fulldoc;
document.body.scrollTo(scrollX,scrollY);
}
});
When the window looks the way you would want to scan, press 'Alt + Q', then press 'Alt + W'.
Now your window will freeze and then you can scan your page.
To steer the objects you need to refresh your browser.
You can resolve the issue with below 2 steps
1 - Add some text in textbox which will populate the dropdown below it .
2 - Use Send Keys Module to scroll down and select the value.
I had a similar issue where we had a popup that only appeared when clicking on a text box. The solution we received from the Tricentis trainer was as follows:
Part One
1. Open your application in Chrome
2. Right click the inspect
3. In the inspector window, on the Elements tab, navigate to your html element where it should be (you can do that by clicking on the element and check that you can see the html in the element)
4. Use the debugger to add a break point there, this should pause it and you should be able to see the elements you need to steer it.
5. Once you found the element, you will need the type of element (e.g. div, span, etc), and the class name
Part two
1. Rescan your module and select any element that matches the criteria of your element selected in Part One #5
2. Identify it by only it's class name property and tag
3. Save and close
4. Edit the element in the module view by changing the class name. This should help you steer it
Note: if the element class name is not unique, you might need to use Explicit name.
Good luck

Selenium WebDriver and xpath locating inside WebElement

I have a page containing multiple forms with their own submit buttons and other elements. While testing the page, I locate the second form
WebElement form = getDriver().findElement(By.id("form2"));
and then field and submit button
form.findElement(By.name("text")).sendKeys("Adding some text here");
form.findElement(By.xpath("//input[#type='submit']")).click();
However these xpath locations take effect on the first form. Is it really so that the xpath doesn't work inside a specified element?
Try a relative path:
form.findElement(By.xpath(".//input[#type='submit']")).click();
In fact Selenium works with the first found by xpath element. If you know exact order number you can add such a number to your xpath //input[#type='submit'][2]. Please note that numbering in xpath starts from 1 but not 0. So given xpath will found for you the second input with #type='submit'.