Puppeteer - Click on tag behind text - node.js

I am quite new to puppeteer and am stuck with trying to click on an element. In the image, that is the "i" element, I want to click on.
When I try to click it, I get the error "Node is either not visible or not an HTMLElement". I guess it is not visible, because there it the nb space in front of it.
Is there a way still to click on it? When I manually click on it, it works, so I would think that puppeteer would also be able to do it?
Thanks,
Benni

After quite some testing I found a way how to click it. First, this didnt work:
page.click(selector)
This brought up the error that specified before.
What worked now was that:
page.evaluate(function (selector) {
const elements = document.querySelectorAll(selector);
elements.forEach((element) => {
element.click();
});
}, selector);
Not sure why the element is coming up multiple times. It should be there only once.
I am not an expert with puppeteer, but happy that this worked. Maybe it helps someone else.

Related

useNavigate: Navigate to external Link

on Clicking of a button, I want to perform an async operation and after that navigate user to an external website as shown below:
navigate("https://wwww.google.com?q=ABC")
But here's the problem:
while using navigate, my url changes like this, because for some reason it's assuming relative path:
http://localhost:3000/https://wwww.google.com?q=ABC
Can someone help me understand what is going wrong? I also tried setting replace to true but no luck there as well.
window.location.href = "https://wwww.google.com?q=ABC";

Selenium , Python and Chrome Webdriver problem

I am learning Python and attempting to build a program that will scrape specific data from a website, store it and then manipulate it.
Currently I run my application, it opens a new chrome browser window and loads the page correctly. The problem is it should begin to start scrolling down and loading the remaining elements on the page.
I know the code works because if I manually click somewhere on the page that doesn't normally illicit a response (white space/empty areas) the browser somehow comes into "focus" and begins to iterate through the loop that scrolls down the page (by sending keys) prints the data I am after. I also noticed if I click another similar "dead space" area that contains the header, it doesn't have the same effect. I am unsure if this is something specific to Chrome, iFrames or something of that nature but I am completely stumped and would greatly appreciate any help.
Any thoughts on why I need to manually click on the new chrome window for it to work would be great.
Update: Still having the same issue, even tried with Safari and the same problem seems to exist.
Fixed this with:
element = driver.find_element_by_css_selector("div[id^='app-container']")
action = ActionChains(driver)
action.click(on_element = element)
action.perform()

Get Tabs URL, copy to new tab, change something in domain

Basically I just want to check links across different environments and thats just a different domain name. So basically I have my extension so far with buttons for each one but am having trouble getting anything to happen. Tried in b ackground.js as I thought that was the only place to access tab?
Tried this and some other variations but yeah this is very new to me so forgive my ignorance. I know javascript well enough but this is taking a bit to adjust.
let dev = document.getElementByID("dev");
console.log(dev);
dev.onclick = function(element) {
chrome.tabs.query({currentWindow: true, active: true}, function (tab) {
chrome.tabs.update(tab.id, {url: "www.google.com"});
});
1) An URL must start with a scheme: https://www.google.com. 2) Make sure to read about the extensions overview::architecture - the popup is a separate page with its own window, URL, and devtools which you can access by rightclicking the popup, then clicking Inspect. 3) Hint: no need to use tabs.query to change the active tab - simply omit tab.id, from tabs.update as it's an optional parameter. – wOxxOm
Thanks that helped a lot!

Using Cypress, how would I write a simple test to check that a logo image exists on a page

specifically, I would like to test that the logo appears on the home page of the app. I guess I am not sure what I should use to look for the image.
I tried
it('has a logo', function () {
cy.visit('http://localhost:3000')
cy.get('img').should('contains' , 'My-Logo.png')
})
instead of cy.get I also tried to just use
cy.contains('My-Logo.png')
but it also fails.
I wasn't sure what element I should use or if I should be using get, but it fails. When I look at the source code for the web page, the logo is hidden within the javascript (nodeJS, vueJS,and expressJS application) and I noticed the javascript seems to add a sequence of numbers and letters to the image when I go to the image page even though the image name in the assets folder does not have it on there. My-Logo.d63b7f9.png.
I figured out the solution on my own.
cy.get('form').find('img').should('have.attr', 'src').should('include','My-Logo')
I inspected the element and found the <img src... line was embedded within a <form>. I could do a cy.get('form') and pass, but could not do a cy.get('img') to pass. So then I chained them together and it passed. I am not sure why I cannot just simply add the second should statement, but it failed when I tried to just run:
cy.get('form').find('img').should('include','My-Logo')
I am not entirely sure why, but it needed the first "should" statement. I got around VUE adding the sequence of numbers and letters by just asking for the name of the file without the extension. I hope this maybe helps someone else as the documentation did not seem to cover this.
you can use only one should statement like:
cy.get('form').find('img').should('have.attr', 'src', 'My-Logo')
the third arg of should is the value to match with the element attribute.

Chrome extension: Copy text

I have a simple chrome extension where I'd like to click an image and copy the href of the link next to it. I have everything in place, but the copy will not work for the life of me. I have the following premissions in my manifest:
"permissions": [
"clipboardRead",
"clipboardWrite"
]
I then create an input with id "copyInp" and use the following function to copy to clipboard (tried to be as deliberate as possible here, so it's not the most compact):
function copyLinkToClipboard( link ) {
$("#copyInp").val(link);
var inp = document.getElementById("copyInp");
inp.focus();
inp.select();
document.execCommand('copy');
};
After this runs, I get nothing new in my clipboard when I ctrl+v. Any ideas as to what's going wrong here? The input definitely has the text I want in it, and I have the permission in the manifest. Any help would be greatly appreciated...
After a bit more digging I discovered I needed to use a background page. Apparently this is the only thing you can call document.execCommand on. So the fix is to create a background.html with the copy function and the input in it, add a listener like so:
chrome.extension.onRequest.addListener(function(obj) {
copyLinkToClipboard( obj.link );
});
and then use sendRequest to pass the text you want copied to the background page:
chrome.extension.sendRequest({link: linkText});
and don't forget to add the background page in the manifest
"background_page": "background.html",
voila. text copied to clipboard. would LOVE an easier way to do this (if security is the issue then why not make an api for extensions? or rather, why scrap the experimental api only to force us to do this stupid workaround?) but oh well, this will suffice for the time being

Resources