Ive got to programmatically click a cookie accept button when a page loads. I tried a few different addons that are showed online. Those did not work...
The button has the following code:
<a id="acceptAllPrivacyOptionsAtag" class="bcGiveConsent bcpConsentButtonAtag bcpConsentOKButtonAtag" aria-label="accept all privacy options" role="button"> accept all cookies </a>
Is there a way to do this in javascript? I have to execute the code in bash shell when the page loads.
Well, there is a thing called Alert() it would be alright when page loads, not the best option tho.
Refering to this answer.
Add a script tag at the bottom portion of your html code and trigger a click event manually.
document.getElementById('acceptAllPrivacyOptionsAtag').click()
Related
Is there a way to get the link of a button click in a website?
This is the Website
https://onlineradiofm.in/stations/mirchi and there is a play button. I want the link to the play button click so that everytime i open the link, the audio starts playing automatically.
Is there a way to achieve this?
Any help is appreciated
Add jquery code in the page where you want to click the button on page load.
<script>
$(document).ready(function()
{
$("#button-id").trigger("click");
})
</script>
Replace button-id with your button id.
There is no link in the play button, it's a click event. The solution to your problem may differ a lot depending if you own the site you are trying to redirect to the audio or not. In case that the website is owned by you, then you could just create the link you are asking for playing with query string parameters to execute a Js script that clicks the button (like the one proposed by #Pranay kumar 's answer). If you don't own the specified website, then its much harder. In this second case, you could make a python script that clicks the button. An example that may guide you to this solution can be found here. This should work in your case, but the solution would not be a link, it would be a script.
I'm trying to click a "Download" button in a pop-up on a webpage. When I click it using Selenium (Chrome; Python), I know it's working because the file gets downloaded.
However, in addition to the javascript that downloads the file, the button has an href=# which should re-direct to the underlying page, (without the pop-up) once it's been clicked. When I click it in a live session using my mouse, the behavior is correct. But when using [button].click() in Selenium, the redirection is not happening - only the file download. Any tips or suggestions?
Edit: code snippets
Here is the button html:
<div class="buttons popup__buttons">
<a href="#" class="button js-downloadLink">
Download
</a>
</div>
And my selenium code:
driver.find_element_by_class_name('button.js-downloadLink').click()
My suggest is to open chrome dev-tools and investigate what action is triggered by javascript. You may need to run a function with selenium that for some reason is not calling when using Selenium or check if the ids are loading properly.
if you want help share the website you want to scrape and we can have a look.
Every website is a new world! Hope it helps.
EDIT:
Still no idea with your snippet. Try the devtool. More precisely to the event listeners where its says click():
I am trying to write a script that clicks on "Buy Now" button on a webpage. You may refer to this link for reference. I have wrote this script:
document.querySelectorAll('._3S6yHr._1i2f2k button')[1].dispatchEvent(new Event('click'))
and this:
document.querySelectorAll('._3S6yHr._1i2f2k button')[1].click()
but none seems to work. How can I overcome this restriction? Any possible workarounds?
PS: jQuery is not available on the page.
I am a first poster here so please excuse my noob-like behavior.
I have a button on my website that when pressed should disappear, and a form should be echoed out in its place without a page refresh.
I have easily achieved this with JavaScript / AJAX, but if JavaScript is disabled, I still want the button to do it's task.
My question is: Can I do this only using PHP, WITHOUT a page refresh?
Cannot comment or I would have but the answer would be no. PHP is server side so the only way for it to update a view is to reload to a new page. Also, I would think it is very unlikely to run into a situation where JS is disabled these days.
Not in a way I think you'd want to do it, but you could use an iframe that contains the button. The button would be a link or form submit and the navigation would happen inside the iframe to your form. This way, only the iframe is refreshed, but the full page remains unchanged.
You can only aciehcve this using ajax. You can force your users to enable
javascript noscript tags
<noscript>
<p>This page requires a JavaScript-enabled browser.</p>
</noscript>
I have a page taken from ThemeForest and I try to examine how it works. If I press one of the links the action taking by the browser is different to one if I just use the anchor link. So I suppose that there is some script run and make the page change more beautiful.
The problem is that I can not understand which script is running in this case: the link has no 'id' tag.
So how do I track the script running upon the link click?