I know there were several examples with selenium option-selecting. Nevertheless, I still cannot select one in one specific website.
https://www.gks.ru/dbscripts/munst/munst20/DBInet.cgi
I want to choose Excel option in the top-left Select.
The HTML is n attachment
I tried approaching the bar this way
for option in el.find_elements(By.TAG_NAME,'option'):
print(option.text)
if option.text == 'CSV':
option.click() # select() in earlier versions of webdriver
break
I also used find_elements by class and css_selector
Then I used
select = Select(driver.find_element(By.TAG_NAME,'Select'))
select.select_by_visible_text('Excel')
It could not locate the element either
Could anyone please help?
To select the select-options with text as CSV from the html-select tag using Selenium you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:
Using CSS_SELECTOR:
select = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "select.Select[name='Format']"))))
select.select_by_visible_text("CSV")
Using XPATH:
select = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//select[#class='Select' and #name='Format']"))))
select.select_by_visible_text("CSV")
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
References
You can find a couple of relevant discussions in:
How to select an option from the dropdown menu using Selenium and Python
Related
I am trying to click through the levels of a site's navigation using python and selenium. The navbar contains list items that have subelements within them.
Here is the html of the navbar:
The objective here is to find the element with id="ts_time", to hover over it and to click on the element within it.
So far I have tried the following selection types:
ID
XPath
Class_Name
Here is the ID.
time_menu_button = driver.find_element(By.ID, "ts_time")
ActionChains(driver).move_to_element(time_menu_button)
time.sleep(2.5)
This results in a NoSuchElementException
To hover over the element with id="ts_time" you need to invoke perform() and then to click on the element within it you can use either of the following locator strategies:
time_menu_button = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "li#ts_time")))
ActionChains(driver).move_to_element(time_menu_button).peform()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li#ts_time > a"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
I know there were several examples with selenium option-selecting. Nevertheless, I still cannot select one in one specific website.
https://www.gks.ru/dbscripts/munst/munst20/DBInet.cgi
I want to choose Excel option in the top-left Select.
The HTML is n attachment
I tried approaching the bar this way
for option in el.find_elements(By.TAG_NAME,'option'):
print(option.text)
if option.text == 'CSV':
option.click() # select() in earlier versions of webdriver
break
I also used find_elements by class and css_selector
Then I used
select = Select(driver.find_element(By.TAG_NAME,'Select'))
select.select_by_visible_text('Excel')
It could not locate the element either
Could anyone please help?
To select the select-options with text as CSV from the html-select tag using Selenium you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:
Using CSS_SELECTOR:
select = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "select.Select[name='Format']"))))
select.select_by_visible_text("CSV")
Using XPATH:
select = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//select[#class='Select' and #name='Format']"))))
select.select_by_visible_text("CSV")
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
References
You can find a couple of relevant discussions in:
How to select an option from the dropdown menu using Selenium and Python
I am tring to access an element inside this iframe:
I tried to use switch_to.frame(0) first, but still can not locate the element inside the frame.
Screenshot of the error:
As the element is within an <iframe> so you have to:
Induce WebDriverWait for the desired frame to be available and switch to it.
You can use either of the following Locator Strategies:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[title='To Do Assignments in Connect'][src='https://connect.mheducation.com/paamweb/index.html#/access/home']")))
Using XPATH:
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[#title='To Do Assignments in Connect' and #src='https://connect.mheducation.com/paamweb/index.html#/access/home']")))
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
References
You can find a couple of relevant detailed discussions in:
How can I select a html element no matter what frame it is in in selenium?
You should switch to the frame:
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
I'm trying to use Selenium to select the 2nd option (with the text "24 words") from the drop-down menu on this page: https://www.myetherwallet.com/wallet/access/software?type=mnemonic
I was able to click on the drop-down menu to display the 2 options using this piece of code:
drop_down_menu = driver.find_element(By.XPATH, '//div[#class="v-select__slot"]')
drop_down_menu.click()
However I was not able to select the 2nd option (or any options). I could not use Selenium Select class because the drop-down menu element is not of Select type element. I tried the below 2 pieces of code without any success:
select_24_words = WebDriverWait(driver, 10).until(EC.text_to_be_present_in_element_value(
(By.CSS_SELECTOR, 'div#list-item-252-1.v-list-item.v-list-item--link.theme--light'),'24'))
select_24_words.click()
and
select_24_words = driver.find_element(By.XPATH, '//div[#id="list-item-252-1"]')
select_24_words.click()
Can anyone help?
Used element_to_be_clickable condition for the xpath - //div[text()='24 words'] and was able to click on 24 word option.
Try like below once.
driver.get("https://www.myetherwallet.com/wallet/access/software?type=mnemonic")
wait = WebDriverWait(driver,30)
wait.until(EC.element_to_be_clickable((By.CLASS_NAME,"v-select__selections"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH,"//div[text()='24 words']"))).click()
The drop-down menu isn't a conventional html-select element so you can't use Select class.
To select the 2nd option (with the text "24 words") from the drop-down menu you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:
Using XPATH:
driver.get("https://www.myetherwallet.com/wallet/access/software?type=mnemonic")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[#class='v-select__selections']"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[#class='v-list-item__title' and text()='24 words']"))).click()
Browser Snapshot:
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
You need to click on the drop-down bar. Then default option.
Then you can click on second option.
All you need is a Explicit Waits.
driver = webdriver.Chrome(driver_path)
driver.maximize_window()
driver.get("https://www.myetherwallet.com/wallet/access/software?type=mnemonic")
default_option = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.v-select__selection--comma")))
default_option.click()
second_option = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[text()='24 words']/ancestor::div[contains(#id,'item')]")))
second_option.click()
Imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
I want to select a certain option by automating using python and selenium. I am able to select the text fields by name but I am unsure how to select the dropdowns in the form.
https://docs.google.com/forms/d/e/1FAIpQLScbs4_3hPNYgjUO-hIa-H1OfJiDZ-FIY1WSk31jGyW5UtQ-Ow/viewform
I have tried using send_keys with getting the element by class but it doesn't seem to work.
driver.find_element_by_class_name("quantumWizMenuPaperselectOption freebirdThemedSelectOptionDarkerDisabled exportOption").send_keys("my choice")
How can I select an option of my choice from the dropdown in the above form ?
It looks like there are multiple elements that are returned for this class.
.find_element_by_class_name
Above returns the first one it finds which happens to not work. The other strategy is to "try-except-click" all of them. See below.
from selenium import webdriver
import time
driver = webdriver.Firefox(executable_path=r'C:\\Path\\To\\Your\\geckodriver.exe')
driver.get("https://docs.google.com/forms/d/e/1FAIpQLScbs4_3hPNYgjUO-hIa-H1OfJiDZ-FIY1WSk31jGyW5UtQ-Ow/viewform")
time.sleep(2)
dropdown = driver.find_element_by_xpath("//div[#role='option']")
dropdown.click()
time.sleep(1)
option_one = driver.find_elements_by_xpath("//div//span[contains(., 'Option 1')]")
for i in option_one:
try:
i.click()
except Exception as e:
print(e)
To select the option with text as Option 2 you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:
Using CSS_SELECTOR:
driver.get('https://docs.google.com/forms/d/e/1FAIpQLScbs4_3hPNYgjUO-hIa-H1OfJiDZ-FIY1WSk31jGyW5UtQ-Ow/viewform')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.quantumWizMenuPaperselectOptionList"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.exportSelectPopup.quantumWizMenuPaperselectPopup div.quantumWizMenuPaperselectOption.freebirdThemedSelectOptionDarkerDisabled.exportOption[data-value='Option 2']"))).click()
Using XPATH:
driver.get('https://docs.google.com/forms/d/e/1FAIpQLScbs4_3hPNYgjUO-hIa-H1OfJiDZ-FIY1WSk31jGyW5UtQ-Ow/viewform')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[#class='quantumWizMenuPaperselectOptionList']"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[#class='exportSelectPopup quantumWizMenuPaperselectPopup']//div[#class='quantumWizMenuPaperselectOption freebirdThemedSelectOptionDarkerDisabled exportOption' and #data-value='Option 2']//span[text()='Option 2']"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC