check page scroll in Chrome naturally (without Selenium) - Python3 - python

Does anyone know of a way to check if the scrollbar in Chrome has reached the bottom without using a detectable module like Selenium? Basically I just want the script to check a page that has already been opened in Chrome in a natural undetectable way to see if the scroll has reached bottom and if it hasn't then execute some code.

Related

Scrolling a pop up window using selenium in python

I have been trying to scroll through the small pop up window from selenium since a while now. I am trying to create an auto follow bot. But I am unable to either follow or scroll through this. I am trying this code but I don't think I am using a correct Xpath.
How can I get the correct Xpath so that I can scroll through the window?
Also when I try to follow without scrolling it throws an error too. So what can be the possible solution for this?
followers_popup= self.driver.find_element(By.XPATH,'//*.
[#id="mount_0_0_vA"]/div/div/div/div[2]/div/div/div[1]
/div/div[2]/div/div/div/div/div[2]/div/div')
for i in range(5):
self.driver.execute_script("arguments[0].scrollTop=
arguments[0].scrollHeight",followers_popup)
time.sleep(5)

Why does the Selenium's program always automatically jump to my desktop

I make a automated crawler for python-selenium but it's always automatically jump to my desktop.
Is it because I recycle swicth to window()?
Please tell me why?
To perform any action within the AUT(Application Under Test) Selenium needs to focus on the elements.
Due to the focus on the Browsing Context, itjumps to the foreground of your desktop.

When i minimize chrome window, selenium stops [duplicate]

I have a project to get some information from website.
I want to look at the process inside the chrome window, So I can't use headless browser. But sometimes I want to minimize the chrome window.
But I found the selenium would go wrong after I minimize the chrome window manually, but sometimes not. When go wrong, exception
element is not clickable at the point, other element will receive the click
will be raised, or sometimes selenium just stop.
I have searched for a long time that some people said that the chrome window should be focused on and can't be minimized by clicking '-' on the window title bar. And the alternative solution is:
web.set_window_position(-2000,-2000)
To make the window move out the screen.
And someone says by simulating shortcuts to minimize the window. But I think it's the same as click '-' manually, am I wrong?
My question is :
Does selenium really requires chrome window not minimized? Why sometimes it can run selenium normally after minimized but sometimes not?
If I use
set_window_position(-2000,-2000)
to move the window invisible, then I click the window icon on the bottom of os (I'm sorry that I don't know what it's called). Normally when clicked, the window will be minimized. So as for this chrome window, Will it be considered as minimized window and go wrong?
I am really sorry for my poor English. I hope I have a clear description of my problem.
Environment:
python 3.6
chrome 66.0
selenium 3.11.0
windows server 2012
Edit to add code:
wait.WebDriverWait(driver,100000).until(EC.visibility_of_element_located((By.ID,'commMgrCompositionMessage')))
textArea = driver.find_element_by_id('commMgrCompositionMessage')
driver.execute_script("arguments[0].value="+"'"+modelStr+"';",textArea)
time.sleep(1)
wait.WebDriverWait(driver,10000).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,'#sendemail_label')))
allSendMailLabel = driver.find_elements_by_css_selector('#sendemail')
allSendMailLabel = allSendMailLabel[1]
driver.execute_script("arguments[0].click();", allSendMailLabel)
If you see the question here Debugging "Element is not clickable at point" error, there is a bug in the chromedriver that causes this. The issue for it was created here. There is a workaround listed in the 27th comment, but what you can do is switch to the firefox driver and see if that works. Minimised windows should not cause a problem otherwise.

Python3.x, How to focus on newly opened webpage

Ok, here's the deal. I use:
driver = webdriver.Firefox(firefox_profile=profile)
driver.get = ('http://google.com')
to open a new webpage. After opening the new webpage, I use pyautogui to do some clicking and scrolling and whatnot, and then close the browser, and then do the same thing over again as the program iterates through a list of proxies. But when the webpage opens, it isn't in focus. I can see it and see that it opened, but it's not in focus.
So I originally implemented a simple click command on the webpage, and that usually focuses the new browser. But after the first browser is opened and closed, the next browser that is opened using a new proxy from the list isn't in focus, and for whatever reason, the click doesn't bring it into focus. So because the browser isn't in focus, my scroll code doesn't happen, it just acts like it skips over it. So I guess my question is, is there some command I can use to make my program focus on the new browser? I've searched extensively on here for the answer to my question and have tried a bunch of different things, but none have worked. Most answers on here pertain to newly opened tabs, and that isn't my issue. Any helpful comments or ideas would be much appreciated. I'm using Mac OS X, and the most recent version of python. Thank you.
Scratch the whole click on the dock icon thing, after extensive testing, that didn't work consistently. However, what did actually work consistently was using pyautogui to click on the "new tab" button at the top, and then close tab, and boom, webpage focused.

Selenium PhantomJS throws EelementNotVisible while Firefox is completely fine during combo box selection

So I have a website which has a combo that I need to select an item from, now the problem is it's a bit untraditional and doesn't have option's as elements but instead it has divs.
So I need my program to click combo box then wait (the best way to do this I found is via implicitly_wait(3)# 3 seconds) and then click the box element I need. Firefox is doing a great job with it but PhantomJS seem to throw:
Selenium.common.exceptions.ElementNotVisibleException:
Message: 'Error Message => \'Element is not currently visible and may not be manipulated\'
I'm not sure what's the cause of it, but I suspect that PhantomJS fails to correctly wait via implicitly_wait for some reason and tries to select non-visible element.
Any idea how to approach this without forced thread sleep?
Yup, your issue sounds exactly something I've just fixed in a UI test that was starting to anoy me. Quite a complex one, that passed on all browsers, except my favorite PhantomJs (which is the fastest).
It was quite anoying, when in the debugger I could clearly see that even the parent element was set to visible. Only the prime faces component I needed to click for whatever reason (not CSS or active Styles) was not visible.
After looking at Phantom JS screenshot, I realized the window was quite tiny, and indeed the UI element was not visually visible.
You see now where I am geting at?
Phantom JS is a headless browser, it does not render you the window, but it does use a window, and the window does have a size.
The exception is quite unexpected, because the engine behind is the same as the one used for chrome and safari ... things should just work.
Well, and they did in the end.
Try to tune your driver factory like this:
WebDriver driver = new PhantomJSDriver();
driver.manage().window().setSize(new Dimension(800, 600));
return driver;
Good luck.

Categories