Issue
I am trying to use the python selenium module to get past a alcohol website 'are you 18+ webpage' check. From the website I am trying to select a region from a dropdown table and the python Select class I pass it through registers but no change is made in the chrome webdriver. Here is what I have so far, any advice would be greatly appreciated. Website is: https://www.shop.liquorland.co.nz/splash.aspx?ReturnUrl=%2f
from selenium import webdriver
from selenium.webdriver.support.ui import Select
def main(website):
"""This function will be set to work with standard superliquor website format to get store details for the database"""
#load webpage
driver = webdriver.Chrome(executable_path='chromedriver_win32/chromedriver.exe')
driver.get(website)
#accept "I am ages 18 or over" button
acceptage = driver.find_element_by_xpath("/html/body/div[1]/header/div[2]/input[1]").click() #working
#select region, something not working below
regionselect = Select(driver.find_element_by_xpath("/html/body/div[1]/main/form/fieldset/div[1]/select"))#.get_attribute('outerHTML')
regionselect.select_by_index(3) #to test, try selecting Northland
#From here, I expect that the webpage region select would be set to Northlands
#NOTE: Yes I have tried regionselect.select_by_value("3") and select_by_visible_text("Northland")
if __name__ == "__main__":
main('https://www.shop.liquorland.co.nz/splash.aspx?ReturnUrl=%2f')
Solution
Unfortunately there is some custom select/dropdown implementation (probably this one), so you need to manually invoke dropdown, and click desired option:
driver.find_element_by_xpath("/html/body/div[1]/main/form/fieldset/div[1]/span").click()
driver.find_element_by_xpath('/html/body//div[contains(@class,"jcf-select-drop-content")]//span[@data-index="2"]').click()
Note: How I got to know a way to invoke dropdown? When you click on a dropdown you can see that <span>
below <select>
is changing it's classes so it should be this element.
Answered By - Whispored2001
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.