I'm struggling to click on a specific object with selenium. HTML CODE
What I've tried so far, unsuccessfully:
webD.find_element_by_link_text('Apply').click()
WebDriverWait(webD, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[3]/div/div/div[4]/div/div[3]/button'))).click()
webD.find_element_by_xpath('/html/body/div[3]/div/div/div[4]/div/div[3]/button').click()
WebDriverWait(webD, 20).until(EC.presence_of_element_located((By.LINK_TEXT, 'Apply'))).click()
And myriads in between. The final code is the one I was most optimistic about.... Turns out the button changes from "close" to "apply" once a selection is done, so I figured by waiting for the element to appear and then click it could work. I think I'm missing something here. Maybe I don't require a wait at all..
Clicking the apply button closes the selection window (which is what I'm trying to do).
Any insight on why these are wrong? Any idea how to correct this issue? Thank you so much in advance! Looking forward to reading your answers.
Use following xpath to click on the button.
WebDriverWait(webD, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(.,'Apply')]"))).click()
Related
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)
How can I tell selenium to press cancel in this case or remove the whole box completely. I looked around and only really saw C# answers. Thank you for your time :)
At first glance, it seems like that's an Alert.
In Python-Selenium you could do this:
Alert = driver.switch_to.alert
Alert.dismiss()
However, It could be a pop-up in HTMLDOM as well. In this case, you will have to find the right locator (CSS, XPath etc.) and perform a click on that cancel button.
I want to click on the button to close the message that is being written.
I try with this code, but it does not work for me:
driver.find_element_by_xpath('//input[#type="Cerrar"]').click()
Can you help me? Thanks very much.
You need to click this element: //img[#alt="Close"]
So, the Selenium python command to do this is
driver.find_element_by_xpath('//img[#alt="Close"]').click()
unless your code needs to use selenium i think that pyautogui would be better for this. it can move your mouse to a specific coordinate or look for the close button and then click it
import pyautogui
pyautogui.moveTo(x=(your x), y=(your y))
pyautogui.click()
i dont know much about selenium so im sorry i cant use that to help you but i hope this helps.
The built-in method close:
The close() method is used to close the current browser window on which the focus is set, on the other hand, the quit() method essentially calls the driver. dispose of a method that successively closes all the browser windows and ends the WebDriver session graciously.
You want to use click when interacting with elements
driver.find_element_by_xpath('//input[#type="Cerrar"]').click()
If that doesn't work, please share the HTML code.
I'm trying to click on some element but it's not working:
driver.find_element_by_xpath("//span[text()='ENG']")
When I add:
driver.maximize_window()
before click action, it works, other codes are not working again.
I had similar problem
When I was looking for an element, it was not yet available in the code.
Fixed by adding
driver.implicitly_wait(30) ## 30 is the time he will wait
before searching for the element.
This line makes the code wait until the entire page is loaded before looking for an element.
I'm trying to click on some element via driver.find_element_by_xpath("//span[text()='ENG']"), but it's not working,
You need to post logs or be more specific. Are you getting an error on the call to find_element_by_xpath(), or when you call click as you mention below?
when I add driver.maximize_window() before click action, it works,
other codes are not working again, please advise which can be the
reason
The relevant code needs to be provided. I believe you're saying that when you call maximize_window() before you locate the element, it works, but if you don't call maximize window, it fails. This could be for a variety of reasons, but it sounds Javascript related. A similar question like this this could help. If maximize window doesn't actually help the issue, I would look into implicit waits or WebDriverWaits.
I am in a project in which I am making a modular behavior driven framework for the company I am working right now. In making a modular approach of the step "user accepts alert", when I test it and came an expected alert box, it automatically closes itself and therefore shows this "NoAlertPresentException: Message: No alert is present" exception.
I have done this codes so far:
def acceptalert():
alert = driver.switch_to.alert
alert.accept()
driver.switch_to.parent_frame()
This code snippet works as I have those modules in which I incorporated the closing of alert box. The only problem is just when I try to make this one a standalone module in my framework. I have done research with this one but I really never got my problem answered. I hope there will be one in here who can help me. Thank you very much.
Found the answer. Thank you. I implemented the step "user clicks '' button" where is the value of the button being matched with a series of xpath and if the xpath returns zero match, then it fetches the available iframes and loops inside each one. When the xpath still returned zero matches, then it switches back to the main frame with this peace of code:
driver.switch_to.parent_frame()
The side effect with this one is it will dismiss the alert boxes. My problem is solved. Thanks everyone.