Python Forum
Selenium click on popup button??? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Selenium click on popup button??? (/thread-15529.html)



Selenium click on popup button??? - GuJu - Jan-20-2019

Hi everyone!
I have been searching for this problem for a week but i couldnt find anything about it.
The problem is this. After i entered the instagram there is a popup so i want to click Not Now button but i couldnt do with xpath or the other things. Can someone help ?? Here you can click the image that shows the problem [Image: cxpRJX3]


RE: Selenium click on popup button??? - Larz60+ - Jan-20-2019

use XPath, and click()
example:
        search_box = browser.find_element(By.XPATH, '//*[@id="quickSearch_BusinessName"]')
        search_box.send_keys(searchitem)
        browser.find_element(By.XPATH, '//*[@id="btn_Search"]').click()
        time.sleep(2)
In Firefox, You can get the XPath of the button, by bringing up site, right click on button and select Inspect Element-->Copy-->XPath


RE: Selenium click on popup button??? - GuJu - Jan-20-2019

Thank you for your message. I've used Chrome Driver, so i use xpath but it is not working, not clicking.
I have tried it but i couldnt do. Can you explain it obviously.
search_box = browser.find_element(By.XPATH, 'xpath way?')
search_box.send_keys(searchitem ???)
browser.find_element(By.XPATH, '//*[@id="Not Now"]').click()
time.sleep(2)



RE: Selenium click on popup button??? - Larz60+ - Jan-20-2019

Actually, I posted the wrong example, should have been and it uses css selector:
page_button_css = 
    'mainContent > table:nth-child(5) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(3) > font:nth-child(1) > a:nth-child(1)'
next_page = self.browser.find_element(By.PARTIAL_LINK_TEXT, 'Next 250')
ActionChains(self.browser).move_to_element(next_page)
next_page.click()
the imports needed are:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By



RE: Selenium click on popup button??? - GuJu - Jan-20-2019

Thank you :) I solve that like this. I have imported these libraries.
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
These xpaths are the same xpath and "Not Now" is the button which one i wanted to click.
search_box = browser.find_element(By.XPATH, '/html/body/div[2]/div/div/div/div[3]/button[2]')
search_box.send_keys("Not Now")
browser.find_element(By.XPATH, '/html/body/div[2]/div/div/div/div[3]/button[2]').click()
So i solve this problem with this. :) Thank you for your help! :)


RE: Selenium click on popup button??? - mlieqo - Jan-20-2019

These two lines from your solution seems redundant to me. Sending keys to a button element does nothing
search_box = browser.find_element(By.XPATH, '/html/body/div[2]/div/div/div/div[3]/button[2]')
search_box.send_keys("Not Now")



RE: Selenium click on popup button??? - GuJu - Jan-20-2019

Yes you are right i tried it a few min. before. Those lines are redundant. :) Thank you for your help and information.


RE: Selenium click on popup button??? - Nizam - Jul-20-2019

(Jan-20-2019, 06:31 PM)GuJu Wrote: Thank you :) I solve that like this. I have imported these libraries.
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By 
These xpaths are the same xpath and "Not Now" is the button which one i wanted to click.
search_box = browser.find_element(By.XPATH, '/html/body/div[2]/div/div/div/div[3]/button[2]') search_box.send_keys("Not Now") browser.find_element(By.XPATH, '/html/body/div[2]/div/div/div/div[3]/button[2]').click() 
So i solve this problem with this. :) Thank you for your help! :)



thank you...this helped me to solve my issue