0

I have searched through the forums and have come upon nothing covering this question. I am looking to add a noise alert in selenium, python webdriver when I find a certain X path. (Like a buzzer or a beep) I have only found info pertaining to pop up alerts when I search for alerts. What I would like to do is have a noise alert when I find a certain link

Driver.get(“google.com”) Driver.find_element_by_text(“search button”).click() 

I want to add an alert when this is clicked for example

1

1 Answer 1

0

You can try this (assuming you are on Windows):

import winsound from selenium import webdriver from selenium.webdriver.common.keys import Keys duration = 1000 # milliseconds freq = 440 # Hz Driver.get(“google.com”) element = driver.find_element_by_name('q') if element.is_displayed(): winsound.Beep(freq, duration) element.send_keys("Python") element.send_keys(Keys.ENTER) print("found") else: print("not found") 
Sign up to request clarification or add additional context in comments.

7 Comments

if element.is_displayed(): AttributeError: 'NoneType' object has no attribute 'is_displayed'
I was assuming your original element was correct, it was not, assuming you are trying to click the search button. I updated the code. BTW you may want to add code to enter some text in the search box first before clicking the button
import winsound duration = 1000 # milliseconds freq = 440 # Hz driver.get("https://www.google.ca/?gws_rd=ssl") time.sleep(5) element = driver.find_element_by_xpath("/html/body/div[1]/div[3]/form/div[2]/div[1]/div[3]/center/input[2]").click() it works up until i add if element is displayed then it gives that error
still getting that error, im not sure whats wrong
Ok, I think I know what the issue is. When google.com loads that button is hidden for some reason, but the search box is not. I changed the code above for testing purposes, to look for the search box instead of the search button. This is just for testing purposes, you will want to add error handling etc to your code
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.