Unable to click the Quality button - python

Any idea on how do I click the quality button as shown in the screenshot using selenium in python.
I am only able to open the settings menu, Not any further.
My main aim is to automatically change the video quality.
Thanks in advance!
list = driver.find_elements_by_name("ytp-settings-button")
list[0].click()

All the operation are dynamic in nature, the use of explicit wait is very important in this case. As per my observation , by using given below steps could help you
click on setting button
wait for object visible of "Quality"
Once found object, then click on it
wait for object visible of "480P" (i.e. required pixel)
once available, click on it.
To get xpath of quality and Pixel go to screenshot.
To stop the loading of element , check the parent tag in which the dynamic element appears and then right click on that tag and select "break on" then "subtree modification". This will stop the loading of website if any changes occur in that tag.

Related

How to click on an element with Selenium without using Driver.get?

So I am trying to write a code to automatically join a google meet. So I need to sign into my google account, which runs all fine but when I get to "Verify that it's you" (image 1), and I try to use driver.get it takes me back to the original sign-in page (image 2)
How can I click on the "Continue" button without using driver.get/without getting taken back to the original sign-in page. I know that all I have to do is click on the "Continue" because when I do it manually it works perfectly. Pressing "Tab" and then "Enter" would also work, but it seems you need to use driver.get as well. Thank you
so i think you don't understand driver.get() usage. it is used only to make the browser browse to a specific link which you can specify before hand. what you have to do here is open the google meet page manually and go to your required page where you want to click the button. right click on the button and click on inspect. then go to the higlighted code and locate the button you want and right click on copy and select xpath from the list. now coming to your code.
add this line:
element=driver.find_element_by_xpath('_xpath')
element.click()
replace _xpath with the long string you copied (which is the xpath of the button you want to click).
this is the way to click on buttons or text boxes or anything you name it in selenium.
**beware of one thing. don't make your code click immediately. if the page does not fully load and the click is made then the 1st line will throw an element not found error. put some kind of delay till page loads or use a while loop and exception handling to wait till the element is found
This one should work for you
userName = driver.find_element_by_xpath("//button[#name='username']")
driver.execute_script("arguments[0].click();", userName)

Python Selenium Webdriver - Handling mouseover on Instagram

I'm creating an Instagram Unfollow Tool. The code usually works, but occasionally Instagram will show the information of some user (as if I hovered over that user) and cause my code to stop running because it obscures the buttons that I need to click in order to unfollow a user.
It's easier to understand with an example:
How can I edit my code to make the mouseover information go away (is there a way to turn off these mouseover effects)?
My code:
for i in range(num_following):
following = self.browser.find_element_by_xpath("/html/body/div[5]/div/div/div[2]/ul/div/li[{}]/div/div[1]/div[2]/div[1]/span/a".format(i))
following_username = following.get_attribute("title")
if following_username not in followers:
# Unfollow account
following_user_button = self.browser.find_element_by_xpath("/html/body/div[5]/div/div/div[2]/ul/div/li[{}]/div/div[2]/button".format(i))
following_user_button.click()
unfollow_user_button = self.browser.find_element_by_xpath("/html/body/div[6]/div/div/div/div[3]/button[1]")
unfollow_user_button.click()
print("You've unfollowed {}.".format(following_username))
The error I get:
selenium.common.exceptions.ElementClickInterceptedException: Message: Element is not clickable at point (781,461) because another element obscures it
It seems like the element unfollow_user_button = self.browser.find_element_by_xpath("/html/body/div[6]/div/div/div/div[3]/button[1]") you want to execute .click() on is blocked by a temporary or permanent overlay.
In such cases you either can wait with ExplicitWait and ExplicitConditions till said blocking element has vanished - though this shouldn't work in this specific case as to my knowledge the popup remains if nothing is done. Another approach is to send the click directly to the element by using the JavascriptExecutor:
#Find the element - by_xpath or alike
unfollow_user_button = driver.find_element_by_xpath("XPATH")
#Sending the click via JavascriptExecutor
driver.execute_script("arguments[0].click();", unfollow_user_button)
Note two things:
driver must obviously be an instance of WebDriver.
I would suggest not using the absolute XPath in general. Going with the relative XPath is less prone to be broken by small changes in the site structure. Click here for a small guide to read through.

How to make selenium identify a button through an attribute within the HTML and click on it automatically whenever it is possible in python

Is it possible to make selenium identify an html button attribute and click on it. So whenever it finds a button attribute it clicks on it automatically. Because I always have to predict around how long it takes for the next button to appear and set time.sleep() but many times it results in errors.
Of coarse it is possible to identify an html button through an attribute and invoke click() on it using Selenium.
But it won't be possible that, whenever a button is found through it's attribute, it can click on it automatically as:
The prediction for how long to wait for the next button to be clickable should be part of your Test Plan or Test Architecture and should be part of the specifications.
Further, using time.sleep(n) defeats the purpose of Automation and should be avoided at any cost.
You can find a relevant detailed discussion in How to sleep webdriver in python for milliseconds
Ideally, you need to remove the all the occurances of time.sleep(n) inducing WebDriverWait inconjunction with the expected_conditions.
You can find a relevant detailed discussion in How to get rid of the hardcoded sleep()?

id of xpath is getting changed every time in selenium python 2.7 chrome

one more problem i hv,i asked similar question earlier and i tried that method but not able use that methon in this problem so pls help me. it's element
html code is - FiltersĀ 
So basically, question is that there is one button its kind of toggle button and i want click on that button to select device like Desktop, Tablet & Mobile all check boxes are already (default) selected now i have to uncheck or deselect device, to do this, first i have to click on that toggle button , when i click on toggle button its id (gwt-uid-598) 598 is getting changed every time or every refresh. Can you pls help me, what should or which method should i follow in this case.
i am using below python code.
Click on device Filters
elem = driver.find_element_by_xpath('//*[#id="gwt-uid-598"]/div/div/span')
elem.click()
Thanks in advance.
Good question.
Try to use another selector, for example: css class or use xpath method contains().
Example: //div[contains(text(), "checkbox")]
I can help you if you can provide source code of the page or needed element.

Selenium: Testing pop-up windows

I have an issue when trying to test a web application with Selenium/Python. Basically I can't test elements of a pop-up window.
A scenario: I can test all elements for a page. But when I go to click on a button that opens up a small pop up box I can't test the elements on the popup. It's like the pop up isn't in focus or active.
I can test elements on the next page. For example click a button, brings me on to next page, and I can work with elements on the 'next' page. So it the problem seems to be popup specific.
I could post code but to be honest it might confuse at this stage. I may post code in a later post, thanks
There is a property called switch_to
Q: How do I handle pop up windows?
A: WebDriver offers the ability to cope with multiple windows. This is done by using the WebDriver.switch_to.window(knownName) method to switch to a window with a known name.
If the name is not known, you can use WebDriver.window_handles to obtain a list of known windows.
You may pass the handle to switch_to.window(handleName)
For example I used driverName.switchTo.window(driverName.getWindowHandle()) to get a hold of popups for which I didn't want to look for names.
Additional references:
http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions
For the Selenium RC API, you need to use the SelectWindow command to switch to the pop-up window. The window can be specified either by its name (as specified on the JavaScript window.open() function) or its title. To switch back to the main window, use SelectWindow(None).

Categories

Resources