Python selenium process exits after ActionChain onclick().perform() - javascript

Please I am not sure what I have done wrong. On the first page I have my code run the following:
next = self.driver.find_element_by_name("checkout_shipping")
actions = ActionChains(self.driver)
actions.move_to_element(next)
actions.click(next).perform()
after clicking next, I want my code to click deliver on the second page:
deliver = self.driver.find_element_by_name("final_shipping_option")
actions_check = ActionChains(self.driver)
actions_check.move_to_element(deliver)
actions_check.click(deliver).perform()
However the second page loads and does nothing. On terminal I get "Process finished with exit code 0" as though everything worked fine when it didn't.

Selenium is a Library that essentially acts as a user. So it loads pages on a browser and manually preforms a click.
I believe your script is finding the correct Element with name "final_shipping_option" but maybe it clicks it too fast for the browser since it's still loading in the Webpage.
Consider trying a time.sleep(x) or something like this:
Wait until page is loaded with Selenium WebDriver for Python
Another possibility is that the name of the element is incorrect, so you're clicking the wrong element? Try to click it via ID, or Class or even XPATH depending on if the page is very dynamic or not..

Related

Oracle apex open file browser automatically on page load

I need to open "File Browse" item ("P50_BLOB") on page load.
I tried clicking the item with dynamic action on page load with javascript:
$('#P50_BLOB').click();
it didn't work, though it does work using the console.
I have also tried using async / wait / promise / wait for document to load.
I even tried to do it with another apex item that will make that click when it is changed, and manually changing the item is working, but on page load it's not.
This is supposed to be very simple but nothing works.
Thanks.
If you try that with the developer tools open in Chrome you will see an error:
Googling that led to this SO question:
File chooser dialog can only be shown with a user activation error while using web scraping through Javascript

Find an element in html source code and show alert message if it`s found

What I am trying to do is pretty simple though I can`t figure it out.
So imagine you browsing a particular website and every time you switch to a new page the source code of html is changing.
I want to popup an alert message if a particular element is found on that page, but if the element is not found I keep browsing, and as soon as this element appears on another page it shows an alert again.
So I`ve got something like this:
function elementCheck(){
if (document.getElementsByName("project_test") {
alert("This page is tested");
}
else {
//keep browsing until this element is found
}
}
You'll need an Userscript for that, ran by TamperMonkey/GreaseMonkey. You just have to invoke the function you already have in the UserScript and that's it.
If the page you're browsing loads HTML asynchronously, via AJAX(i.e. the source code changes without changing the URL), you need to call your function periodically via setInterval.

Elements wont function in Chrome binary driver on a specific page

A specific page in the site I am testing have few buttons that wont register any clicks via selenium Webdriver or manual clicks while opened with chrome binary driver. It works fine while I manually test it in chrome browser.
I tried adding waits, javascript click, action click for selenium with no success.
Webdriver is not throwing an error for clicking/finding element as its doing as it supposed to (I think) but since the page is not responding and not moving forward to the next, I am getting a page object error
Hard to help without specific details, but here's my best attempt:
Potential Problem 1. Make sure the element is not on an iframe, if so here's a link explaning how to fix your code:
How to switch frames - Selenium - Java
Potential Problem 2. Open an incognito/alternate tab, access the same page and check that the CSS Selector/X-Path you are using is existent and pointing to the correct element. If that is not the case, try to correct it by looking at the classes that did not change from the previous Selector to the new.

Opening a webpage and automatically calling an OnClick function

We have a small group of guys who play the game below. We take these games and stream them on Twitch so we can watch them as a group live. We have gotten down the process of automatically opening the URL and streaming the games. However, to get the plays to show there is an OnClick function that we have to manually remote in each time and click. Is there a way we can open this webpage and simulate the click so they are turned on? If you click the link below, you'll see a yellow button called Plays. If you click it you'll see what we want to be able to turn on without manually having to do it.
http://glb2.warriorgeneral.com/game/replay/171542
This depends a lot on how you're automating the page opening.
Normally, you can simply call .click() on an element in JS. But since you want to click something on a page you don't control, it gets complicated.
If you're simply opening a new tab/window via Javascript, you won't be normally able to do this because of cross-domain JS protections. You can disable them which is not recommended--if you go this path, you'll want to load the page in an iframe and execute a callback on it: see this answer. The callback you'll want will look something like:
function(){ window.frames[0].document.getElementById('toggle_plays').click(); }
Knowing how you're doing the automation would help significantly on how to solve the problem within your limits.

Am I able to track the executed Java scripts in Chrome?

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?

Categories