How can I click this button? - python

The element isn't being recognized, I'm trying to click the button after I put in a file submission. I tried having the keyboard press enter as an alternate solution but it doesn't work.
Image of HTML
def ClickButton():
action = ActionChains(web)
button_path = wait.until(ec.presence_of_element_located((By.XPATH,"//*[local-name()='svg' and #data-qa='send-message']/*[localname()='path']")))
# click the item
action.move_to_element(button_path)
action.click(on_element=button_path)
# perform the operation
action.perform()

Try CSS:
button = driver.find_element_by_css_selector('svg[size="24"] \
[data-qa="send-message"] \
[data-button-disabled="false"]')
button.click()

Related

radio button in google form with selenium python

I was writing a web scraper in python using selenium on a google form page, but i want to be able to select a particular button that i want. i tired selecting all the buttons once so it ended up selecting the last one as expected. Going through a multiple of a number is also not possible as each contain different number of buttons.
So i want a way to get the number of radio buttons in a group and a way to select the desired one.
Test site
If there are any other suggestions then i will be happy to listen ?
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import Resources
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome(executable_path= Resources.driverChrome)
driver.maximize_window()
driver.get(Resources.linkTest)
time.sleep(3)
try:
email = driver.find_element_by_xpath("//input[#type='email']")
if email.is_displayed() & email.is_enabled():
email.send_keys(Resources.emailTest)
except:
print("Email box was not found")
containers = driver.find_elements_by_xpath("//div[#class ='freebirdFormviewerViewNumberedItemContainer']")
sNoBoxes = driver.find_elements_by_xpath("//input[#type='text' ] ")
time.sleep(2)
radios = driver.find_elements_by_xpath("//div[#class='appsMaterialWizToggleRadiogroupOffRadio exportOuterCircle']")
for radio in radios:
radio.click()
for container in containers:
sNo = int(containers.index(container))
print("\n\n" + str(sNo) + " " + container.text)
button = driver.find_element_by_xpath("//span[contains(text(),'Submit')]")
button.click()
time.sleep(3)
try:
viewScore = driver.find_element_by_xpath("//span[contains(text(),'View score')]").click()
except:
pass
First, you can find all radio buttons on the webpage with the following code:
radiobuttons = driver.find_elements_by_class_name("appsMaterialWizToggleRadiogroupElContainer")
Result: a list of radio button elements
Next, you are going to count the radio buttons. Note that radio buttons are global; The radio button "Option 2" is the 11th button instead of 2nd. If you want to click the very first radio button, use:
radiobuttons[0].click()
Result: the radio button is clicked
To click the n th radio button, use:
radiobuttons[n-1].click()

Clicking a Button in a formbox with selenium WebDriver in python

I am new to python and selenium. I am trying to click a button in a formbox, but cannot click, only highlight the button. I am trying to click on the button named "Delivery System"
My code is:
delivery_system = browser.find_element_by_name("Delivery System")
browser.execute_script("arguments[0].click();", delivery_system)
delivery_system.click()
The html is:
HTML Code
When I try my code it just highlights the button, but doesn't click/follow it?
ANy ideas?
i would advice you change
delivery_system = browser.find_element_by_name("Delivery System")
browser.execute_script("arguments[0].click();", delivery_system)
delivery_system.click()
to
delivery_system = browser.find_element_by_name("Delivery System").click()
or select by classname
driver.find_element_by_css_selector('.browseLink').click()

Python Selenium: I can't click this exit button

The exact button I am trying to click is this:
https://www.bungol.ca/map/location/toronto/?
close the property slider on the left
click tool -> open list
click on any of the listing and you get to something like this:
Image for close button
Here's what I tried to do:
time.sleep(5) #wait for page to fully load
driver.find_element_by_xpath("""/html/body/div[17]/div/div/div/button""").click()
and
time.sleep(5) #wait for page to load
driver.find_element_by_css_selector("""html body#body.modal-open div#listingInfoModal.modal.fade.show div.modal-dialog.modal-xl div.modal-content div.modal-body button.close""").click()
This CSS selector will do it.
#listingInfoModal button.close

How click on right click menu in selenium python?

I am trying to click on right click menu and i am able to open the right click menu but its not clicking on any menu or not pressing any keys like down , up etc where i am wrong :
profile_pic=driver.find_element_by_css_selector('img[class="profilePic img"]')
okl=profile_pic.click()
time.sleep(5)
action1=ActionChains(driver)
action1.context_click(okl).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform()
here is a working version to do it:
first right click to show up the menu
menuDiv = browser.find_element_by_xpath("//<selector>']")
actionChains.move_to_element(menuDiv).perform()
actionChains.context_click().perform()
then locate the submenu item you want to click on
time.sleep(3) //better wait for a little while
targetMenu = browser.find_element_by_xpath("//<selector>")
actionChains.click(targetMenu)
actionChains.perform()

How to click on a context menu- popup menu

I need to do the following:
1) Right click on a element
2) Context menu is displayed
3) On moving
to a specific menu (move_to_element) in context menu - pops up
another menu say MenuX
4) Need to click on MenuX
I am able to do steps 1 to 3 but not 4.
When I checked is_displayed for MenuX it returns False
When I try driver.find_element_by_xpath("html/body/div[5]/span[2]")
it works (I do not want to hardcode).
But not with id of menu.
Also tried but no luck
actions = ActionChains(driver)
actions.move_to_element(menu)
actions.click(hidden_submenu)
actions.perform()
I also tried driver.find_element_by_css_selector("div#contextMenu_Div #menuX") and it didn't work.
MenuX is not link but a span element.
Try to use below code in order to click on the sub menu item after right clicking:
WebElement element = driver.findElement("Find the element on which right click needs to be performed"));
Actions actions = new Actions(driver).contextClick(element);
WebElement mainMenu = driver.findElement(By.linkText("menulink"));
actions.moveToElement(mainMenu);
WebElement menuX = driver.findElement(By.cssSelector("subLinklocator"));
actions.moveToElement(menuX);
actions.click().build().perform();
Hope this helps
Can you try this..
Actions actions = new Actions(driver);
actions.contextClick(mainelement);
actions.moveToElement(menuelement);
actions.perform();
//at this point ur MenuX shd be visisble.
driver.findElement("locator for ur MenuX").click();

Categories

Resources