Such a great teacher you are.Thankyou for your service!
@RaghavPal11 ай бұрын
Most welcome
@mowtown75 Жыл бұрын
Great, I understand more about what I am doing now, which will let me move from 'assembling code' to 'writing code'. Thanks!
@RaghavPal Жыл бұрын
You're welcome Tibby
@wangarewakungu9753 Жыл бұрын
You are amazing. Watching you from Denmark. Thank you for detailed and clear lesson.
@RaghavPal Жыл бұрын
You're very welcome
@prasannakamble1896 Жыл бұрын
As You always say in video End, For Us Never Stop Learning, and For You Never Stop Sharing.. 😊 We Both practice Together and make Each concept clear from scratch - Raghav sir Again Thanks for This Entire Series..🎉
@RaghavPal Жыл бұрын
Yes, you are right Prasanna
@rickybrown82646 күн бұрын
Hey Ragav, your videos are great! I am following along till 8:27 but when I run my code it takes me to a 'are you a robot' verification page. Its just a checkbox, is it possible to get Selenium to check that or is that the whole point of the check? Thanks!
@rickybrown82646 күн бұрын
There is also a banner at the top saying "Chrome is being controlled by automated software". I tried passing the robot check manually to see if it would ask me again and it seems to ask me each time.
@rickybrown82646 күн бұрын
Tried to trick it with this, did not work haha googleSearchBar = driver.find_element(By.ID, "APjFqb") googleSearchBar.send_keys("A") time.sleep(1) googleSearchBar.send_keys("u") time.sleep(1) googleSearchBar.send_keys("t") time.sleep(1) googleSearchBar.send_keys("o") time.sleep(1) googleSearchBar.send_keys("m") time.sleep(1) googleSearchBar.send_keys("a") time.sleep(1) googleSearchBar.send_keys("t") time.sleep(1) googleSearchBar.send_keys("i") time.sleep(1) googleSearchBar.send_keys("o") time.sleep(1) googleSearchBar.send_keys("n") time.sleep(1) googleSearchBar.send_keys(Keys.ENTER)
@rickybrown82645 күн бұрын
Guess Ill use a dummy site and just follow along. Challenge accepted!
@RaghavPal5 күн бұрын
ok
@s.praveenkumar7109 Жыл бұрын
Thank you for the knowledge Sir! How do we find a word/text say for example "India is my country" in a webpage and double-click on it? Note: Chrome is already opened.
@RaghavPal Жыл бұрын
Praveen Here's how to find a word/text in a webpage and double-click on it using Selenium Python: ```python from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains # Locate the text using appropriate strategy text_to_find = "India is my country" text_element = driver.find_element(By.XPATH, f"//body//*[contains(text(), '{text_to_find}')]") # Double click on the text element actions = ActionChains(driver) actions.double_click(text_element).perform() ``` This code performs the following steps: 1. **Imports necessary libraries:** - `selenium.webdriver`: Provides the WebDriver class for browser automation. - `selenium.webdriver.common.by`: Defines methods for locating elements on the webpage. - `selenium.webdriver.common.action_chains`: Provides classes for performing complex mouse and keyboard interactions. 2. **Defines the text to find:** Replace "India is my country" with your desired text. 3. **Locates the text element:** - Uses By.XPATH with a wildcard search for any element containing the specified text. - You can adjust the locator strategy based on your specific HTML structure. 4. **Creates an ActionChains object:** Allows you to chain multiple actions together. 5. **Double-clicks on the text element:** Uses the `double_click` method and performs the action. This example assumes Chrome is already opened and the relevant webpage is loaded. You need to replace `driver` with your actual browser instance obtained using `webdriver.Chrome()` or other relevant browser driver. **Alternative locators:** - `By.CSS_SELECTOR`: You can use CSS selectors to locate the element, assuming the text has a specific identifier or class. - `By.ID`: If the text element has a unique ID, you can use `By.ID` for faster identification. **Additional tips:** - Use explicit waits to ensure the element is visible before interacting with it. - Consider using regular expressions for more flexible text matching. - You can modify the code to handle multiple occurrences of the text and double-click on a specific one. By adapting this code and adjusting the locators based on your specific webpage structure, you can effectively find and double-click on any text element using Selenium Python.
@ishanpal9779 Жыл бұрын
Again great work..
@RaghavPal Жыл бұрын
Thanks
@IslamAshraf-u6h Жыл бұрын
Great Work.. Thanks
@RaghavPal Жыл бұрын
You are welcome Islam
@user-dk8oj9xo2j8 ай бұрын
Thank you
@RaghavPal8 ай бұрын
Most welcome
@data-for-us Жыл бұрын
Thank you for an amazing tutorial. Can you guide how to access buttons inside the dropdown menu and gets enabled when the dropdown
@RaghavPal Жыл бұрын
Arooj To access buttons inside a dropdown menu in Selenium Python, you can use the following steps: 1. Locate the dropdown menu element. You can use the `find_element_by_css_selector()` or `find_element_by_xpath()` method to locate the dropdown menu element by its CSS selector or XPath. 2. Click on the dropdown menu element. You can use the `click()` method to click on the dropdown menu element. 3. Wait for the dropdown menu to open. You can use the `implicitly_wait()` method to wait for the dropdown menu to open. 4. Locate the buttons inside the dropdown menu. You can use the `find_elements_by_css_selector()` or `find_elements_by_xpath()` method to locate the buttons inside the dropdown menu by their CSS selector or XPath. 5. Interact with the buttons inside the dropdown menu. You can use the `click()`, `is_enabled()`, and other methods to interact with the buttons inside the dropdown menu. Here is an example of a Selenium Python script that accesses buttons inside a dropdown menu: ```python from selenium import webdriver driver = webdriver.Chrome() # Locate the dropdown menu element. dropdown_menu = driver.find_element_by_css_selector(".dropdown-menu") # Click on the dropdown menu element. dropdown_menu.click() # Wait for the dropdown menu to open. driver.implicitly_wait(10) # Locate the buttons inside the dropdown menu. buttons = driver.find_elements_by_css_selector(".dropdown-item") # Interact with the buttons inside the dropdown menu. for button in buttons: if button.is_enabled(): button.click() # Close the browser. driver.quit() ``` You can modify this script to automate the specific dropdown menu that you are working with. Here are some additional tips for automating dropdown menus in Selenium Python: * Use the `Select` class to select options from a dropdown menu. The `Select` class provides a number of methods for selecting options from a dropdown menu, such as `select_by_visible_text()`, `select_by_value()`, and `select_by_index()`. * Use the `Actions` class to interact with dropdown menus in a more complex way. For example, you can use the `Actions` class to hover over a dropdown menu and click on an option. * Use a third-party library to automate dropdown menus. There are a number of third-party libraries that can help you automate dropdown menus, such as the `SeleniumExtras` library. I hope this helps!
@mallikarjunag4078 Жыл бұрын
great sir please cover all topics related to python selenium and thanks for starting series
@RaghavPal Жыл бұрын
Sure I will
@ВикторияПетросян-ц8ш9 күн бұрын
thank you so much :)
@RaghavPal9 күн бұрын
Most welcome
@flirtuall787 ай бұрын
Thanks for sharing.
@RaghavPal7 ай бұрын
Most welcome
@roshnimaurya578026 күн бұрын
I have followed the same code, but my code is not able to click on the search bar and enter the word because a sign-in pop-up comes up. What do I do to ignore that and get the search element clicked? Thanks
@RaghavPal25 күн бұрын
Roshni Here’s what you can do step by step: 1. Handle the Pop-up First: - Use Selenium to detect and close the pop-up. ```python try: popup = driver.find_element(By.XPATH, "POPUP_CLOSE_BUTTON_XPATH") popup.click() except: print("No pop-up found.") ``` 2. Wait for the Pop-up to Disappear: - Add an explicit wait to ensure the pop-up is handled. ```python from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC WebDriverWait(driver, 10).until(EC.invisibility_of_element((By.XPATH, "POPUP_XPATH"))) ``` 3. Click on the Search Bar: - Now locate the search bar and click. ```python search_bar = driver.find_element(By.XPATH, "SEARCH_BAR_XPATH") search_bar.click() search_bar.send_keys("Your Search Term") ``` 4. Retry If Needed: - If the pop-up reappears, handle it again in a loop. -
@ammar_hassan709 Жыл бұрын
Raghav what is the schedule for the upcoming videos and thank you for this great tutorial
@RaghavPal Жыл бұрын
I will add new videos every week
@wahidurrahman7506 Жыл бұрын
hi @Ragav, Whenever I am trying to access the google page, a google terms and condition page pops up. how do I deal with that?
@RaghavPal Жыл бұрын
Wahidur There are two ways to deal with the Google terms and conditions page when using Selenium Python: 1. **Click the "Accept" button on the page.** This is the simplest way to deal with the page, but it requires your script to wait for the page to load and the button to become visible. You can do this using the following code: ```python from selenium import webdriver driver = webdriver.Chrome() driver.get("www.google.com") # Wait for the terms and conditions page to load terms_and_conditions_page = driver.find_element_by_id("terms-of-service-link") # Click the "Accept" button terms_and_conditions_page.click() ``` 2. **Set the `accept_cookies` flag to True.** This will make Selenium automatically accept the cookies on the terms and conditions page without having to click any buttons. You can do this using the following code: ```python from selenium import webdriver driver = webdriver.Chrome() driver.get("www.google.com") # Set the "accept_cookies" flag to True driver.accept_cookies = True ``` Which method you use depends on your specific needs. If you need your script to wait for the terms and conditions page to load and the user to accept the cookies, then you should use the first method. If you need your script to start interacting with the page as soon as possible, then you should use the second method. **Note:** It is important to note that using the second method will prevent the user from reading and understanding the terms and conditions before accepting them. This may not be ideal for all situations.
@Sofianimaulidya-fw4gu Жыл бұрын
Hi Raghav why can't the Button be clicked? even though there was no error message in the terminal and I took the element using selectorhub could you help me please?
@RaghavPal Жыл бұрын
Sofiani There are a few reasons why a button might not be clickable in Selenium Python, even if there is no error message in the terminal. * The button might not be visible on the page. This can happen if the button is hidden by another element, or if it is located outside of the viewport. * The button might not be enabled. This can happen if the button is disabled by the website, or if the user does not have the required permissions to click it. * The button might not be interactable. This can happen if the button is a decorative element, or if it is not part of the main content of the page. To troubleshoot this issue, you can try the following: * Check the visibility of the button. You can use the `is_displayed()` method to check if the button is visible. * Check the enabled state of the button. You can use the `is_enabled()` method to check if the button is enabled. * Check the interactability of the button. You can use the `is_interactable()` method to check if the button is interactable. If the button is visible, enabled, and interactable, then it is possible that there is a problem with the Selenium code that is trying to click the button. You can try debugging the code to find the problem. Here are some additional things to keep in mind: * Make sure that you are using the correct locator to find the button. * Make sure that you are using the correct method to click the button. * Make sure that you are waiting for the button to be clickable before you try to click it. I hope this helps
@shijinap928011 ай бұрын
When I try to execute the automation,the google sign-in page appear.And I can't locate the element of 'stay sign out' button;I got error.pls help me
@RaghavPal11 ай бұрын
Can try this: 1. Locating the Element: - To find and click the "Not Now" button, you can use the following XPath: ```python driver.find_element_by_xpath("//button[text()='Not Now']").click() ``` - However, keep in mind that the element might be dynamic, so it's essential to wait for it to become clickable. You can use WebDriverWait along with Expected Conditions: ```python from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC # Wait for the element to be clickable WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div//button[text()='Not Now']"))).click() ``` 2. Alternative Approaches: - Sometimes, the "Sign Out" link may not be directly accessible. In such cases, try clicking on the username first (if visible) to reveal the logout button: ```python # Click on the username (assuming it reveals the logout button) driver.find_element_by_xpath("//div[@id='userNavButton']/span").click() # Now click on the logout button driver.find_element_by_xpath("//a[contains(text(),'Logout')]").click() ``` 3. Documentation and Learning: - For more scenarios and detailed documentation, explore the Selenium documentation and community resources. You can find relevant discussions on platforms like Stack Overflow and GeeksforGeeks. - Remember to adapt these solutions to your specific use case, considering any variations in your application's structure. ..
@hazemahmedibrahimibrahim7090 Жыл бұрын
Hi Raghav, I keep getting this error when try to execute the code for clicking on google search button raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
@RaghavPal Жыл бұрын
Hazem The error message "element not interactable" means that the element you are trying to click on is not in a state where it can be interacted with. This can happen for a variety of reasons, such as: * The element is hidden. * The element is disabled. * The element is not yet loaded. To fix this error, you need to make sure that the element is in a state where it can be interacted with. Here are some specific things you can do: * Check the CSS properties of the element to make sure that it is not hidden. * Check the HTML markup of the element to make sure that it is not disabled. * Use a wait statement to wait until the element is loaded. Here is an example of how you can use a wait statement to wait until the element is loaded: ```python from selenium import webdriver driver = webdriver.Chrome() driver.get('www.google.com') search_button = driver.find_element_by_id('search_button') wait = WebDriverWait(driver, 10) wait.until(EC.element_to_be_clickable(search_button)) search_button.click() ``` This code will wait for up to 10 seconds for the search button to be clickable. If the search button is not clickable after 10 seconds, an error will be raised. I hope this helps
@wangarewakungu9753 Жыл бұрын
How do i pass the current chrome version to avoid selenium picking chrome 115? thank you
@RaghavPal Жыл бұрын
Wangare To pass the current Chrome version to avoid Selenium picking Chrome 115, you can use the `desired_capabilities` parameter when you create a new Selenium WebDriver instance. The `desired_capabilities` parameter is a dictionary that allows you to specify the desired capabilities of the browser that you want to use. To pass the current Chrome version, you can add the `chrome_version` key to the `desired_capabilities` dictionary and set the value to the current Chrome version. For example, if the current Chrome version is 100, you would use the following code: ```python from selenium import webdriver chrome_version = "100" desired_capabilities = { "chrome_version": chrome_version, } browser = webdriver.Chrome(desired_capabilities=desired_capabilities) ``` This will create a new Chrome WebDriver instance that uses Chrome 100. You can also use the `executable_path` parameter to specify the path to the Chrome executable file. This can be useful if you want to use a specific version of Chrome that is not installed on your system. For example, to use Chrome 99, you would use the following code: ```python from selenium import webdriver chrome_version = "99" executable_path = f"/path/to/chrome-{chrome_version}.exe" desired_capabilities = { "chrome_version": chrome_version, } browser = webdriver.Chrome(executable_path=executable_path, desired_capabilities=desired_capabilities) ``` This will create a new Chrome WebDriver instance that uses Chrome 99. I hope this helps
@Programmingworld-g9m6 ай бұрын
Is dirver. close() is necessary?
@RaghavPal6 ай бұрын
In Selenium, `driver.close()` is a method that closes the current window or tab of the browser instance. This method does not quit the entire browser session, but rather closes the current window or tab, allowing you to continue interacting with the browser instance if there are other windows or tabs open. On the other hand, `driver.quit()` is a method that quits the entire browser session, closing all windows and tabs, and shutting down the WebDriver service. When is `driver.close()` necessary? `driver.close()` is necessary in the following scenarios: 1. Multiple windows or tabs: If your test opens multiple windows or tabs, you might want to close each window or tab individually using `driver.close()` to ensure that the test doesn't interfere with other tests or leave unnecessary windows open 2. Resource management: Closing unnecessary windows or tabs can help manage system resources, especially when running tests in a resource-constrained environment 3. Test isolation: Closing the current window or tab can help isolate each test, ensuring that the next test starts with a clean slate When can `driver.close()` be skipped? `driver.close()` can be skipped in the following scenarios: 1. Single window or tab: If your test only opens a single window or tab, you can skip `driver.close()` and use `driver.quit()` to close the entire browser session 2. Implicit cleanup: Many test frameworks, such as Pytest or Unittest, provide implicit cleanup mechanisms that automatically close the browser instance after each test. In such cases, `driver.close()` might not be necessary Best practice As a best practice, it's recommended to use `driver.quit()` instead of `driver.close()` whenever possible. `driver.quit()` ensures that the entire browser session is closed, which can help prevent resource leaks and ensure a clean test environment. However, if you need to close individual windows or tabs, `driver.close()` can be useful. Just remember to use `driver.quit()` eventually to close the entire browser session ..
@prashanthreddyburri Жыл бұрын
hi @Ragav, could you give code for dropdown selection, for multi-select and single select for the same example.
@RaghavPal Жыл бұрын
Hi Prashanth Here is the code for dropdown selection, for multi-select and single select for the same example: ```python from selenium import webdriver from selenium.webdriver.common.by import By def select_option_by_index(driver, element_id, index): driver.find_element(By.ID, element_id).select_by_index(index) def select_option_by_value(driver, element_id, value): driver.find_element(By.ID, element_id).select_by_value(value) def select_option_by_visible_text(driver, element_id, text): driver.find_element(By.ID, element_id).select_by_visible_text(text) def main(): driver = webdriver.Chrome() driver.get("www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple") # Select option by index select_option_by_index(driver, "cars", 2) # Select option by value select_option_by_value(driver, "cars", "Volvo") # Select option by visible text select_option_by_visible_text(driver, "cars", "BMW") driver.quit() if __name__ == "__main__": main() ``` This code will open the W3Schools website and select the options in the "cars" dropdown list by index, value, and visible text. To run the code, you can save it as a Python file and then run it from the command line. For example, if you save the code as `dropdown_selection.py`, you can run it by typing the following command into the command line: ``` python dropdown_selection.py ``` This will run the code and open the W3Schools website. The dropdown list will be populated with the options "Volvo", "BMW", and "Audi". The option "BMW" will be selected by default. You can then select the other options by index, value, or visible text. I hope this helps
@satishreddybojanpally9824 Жыл бұрын
Practicing the file will be there is no such driver by url telling what can I do sir I have windows 7
@RaghavPal Жыл бұрын
Hi Satish The error message "No such driver by url" means that Selenium cannot find the driver that you are trying to use. This can happen for a few reasons: * You may not have installed the driver correctly. * The driver may not be compatible with your version of Selenium. * The driver may not be compatible with your operating system. If you are using Windows 7, you need to make sure that you have installed the correct version of the ChromeDriver for Windows 7. You can download the ChromeDriver from the ChromeDriver website: chromedriver.chromium.org/downloads. Once you have downloaded the ChromeDriver, you need to extract the zip file and save the executable file to a location on your computer. Then, you need to update the path to the ChromeDriver in your Selenium code. Here is an example of how to update the path to the ChromeDriver in your Selenium code: ```python from selenium import webdriver driver = webdriver.Chrome(executable_path="C:\Program Files (x86)\chromedriver.exe") ``` Once you have updated the path to the ChromeDriver, you should be able to run your Selenium code without any errors. If you are still getting the error message "No such driver by url", you can try the following: * Check the version of Selenium that you are using. You need to make sure that you are using a version of Selenium that is compatible with the driver that you are trying to use. * Check the operating system that you are using. You need to make sure that you are using a driver that is compatible with your operating system. * Try a different driver. There are other drivers available for Selenium, such as the FirefoxDriver and the EdgeDriver. You can try using a different driver if you are still getting the error message "No such driver by url". I hope this helps
@roshnimaurya578026 күн бұрын
I tried with other sites as well other than google still google page is opening.
@RaghavPal25 күн бұрын
will need to check more details Roshni
@0xQwerty-x5e Жыл бұрын
I'm having an error importing By. The error says "Import By could not be resolved."
@RaghavPal Жыл бұрын
Leoniel The error message "Import By could not be resolved" means that the `By` module is not installed in your Python environment. The `By` module is a part of the Selenium library I hope you have installed Selenium in your project, can check the part 1 video Then add import statement to import By library in your code from selenium.webdriver.common.by import By
@mhierrog91 Жыл бұрын
Hi! I'm not able to pass line 11 of your code even if y copy and paste, could you help me? Thanks
@RaghavPal Жыл бұрын
will need more details Mario, pls give me timestamp and more details
@mhierrog91 Жыл бұрын
@@RaghavPal hi! Thanks for your response, I have already solved the issue
@LaliteshParihar-zv8ml Жыл бұрын
Good
@RaghavPal Жыл бұрын
Thanks Lalitesh
@ankursharma7134 Жыл бұрын
@Raghav Sir - Getting below mentioned error while clicking on Google Search button. selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable Could you please help me out on this?
@RaghavPal Жыл бұрын
Hi Ankur Sure, I can help you with that. The error message "selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable" means that the element that you are trying to interact with is not interactable. This can happen for a number of reasons, including: * The element is not visible. * The element is disabled. * The element is hidden. To troubleshoot this error, you can try the following: * Make sure that the element is visible. You can do this by checking the visibility of the element using the `is_displayed()` method. * Make sure that the element is enabled. You can do this by checking the enabled state of the element using the `is_enabled()` method. * Make sure that the element is not hidden. You can do this by checking the visibility of the element's parent element. If you have checked all of these things and you are still getting the `ElementNotInteractableException` exception, you can try posting a question on the Selenium forum or mailing list. There are a number of experienced Selenium users who can help you troubleshoot the error. Here is an example of how to check the visibility of an element using the `is_displayed()` method: ```python from selenium import webdriver driver = webdriver.Chrome() driver.get("www.google.com") search_box = driver.find_element_by_id("search") if search_box.is_displayed(): print("The search box is visible.") else: print("The search box is not visible.") ``` Here is an example of how to check the enabled state of an element using the `is_enabled()` method: ```python from selenium import webdriver driver = webdriver.Chrome() driver.get("www.google.com") search_box = driver.find_element_by_id("search") if search_box.is_enabled(): print("The search box is enabled.") else: print("The search box is not enabled.") ``` I hope this helps
@pilyotuts11 ай бұрын
how to interact in pseudo-elements? ::after
@RaghavPal11 ай бұрын
need more details on this..
@ershelin Жыл бұрын
could you tell me how to do this code in google colab