Thank you for taking a look at my question, I appreciate your help.
I looked around at the available answers and none of them seem to work for me. Other answers seem to deal with switching to an iframe, which I do successfully (otherwise it would crash sooner, right?), then I can't select a dropdown menu in that iframe.
Some of the approaches I tried:
Unable to click on dropdown within iframe - Selenium Python
Can't access dropdown select using Selenium in Python
Python Selenium - Cant Click on Button (iFrame Solved !)
For some reason the element isn't there - I tried using wait statements (both sleep and EC.waits) but that also didn't work. When I observe the program run, I can see that the driver successfully loads the iframe and the elements are selectable, so I think it may be a misunderstanding in how you access iframe elements.
Here is the code, you'll notice it is behind a login block, I don't know what I can do in this case to help people get to that point, but I have shared all the html and code I can think of and can share more upon request:
def clear_wardrobe():
"""Clears the user's wardrobe so that they have no items listed"""
try:
# Initialize
log_in()
# Fetch the number of items on the page and loop through all of them.
while True:
driver.get("https://www.grailed.com/users/myitems")
time.sleep(2)
item = driver.find_element_by_xpath("//*[@id=\"wardrobe\"]/div/div[3]/div/div[2]/div[2]/div/div[1]/div[1]/a/div[2]/img")
item.click()
time.sleep(3)
driver.switch_to.window(driver.window_handles[1])
element = driver.find_element_by_xpath("/html/body/div[8]/div/div[2]/div[3]/div[9]/div[2]/span/a")
actions = ActionChains(driver)
actions.move_to_element(element).perform()
time.sleep(0.5)
element = driver.find_element_by_xpath("//*[@id=\"Listing--Actions\"]/div/div[1]")
element.click()
time.sleep(1)
# switch to specific iframe and select "Sold Elsewhere option" - ISSUE IS HERE
frame = driver.find_element_by_xpath("//iframe[contains(@title,'Optimizely Internal Frame')]")
driver.switch_to.frame(frame)
select_box = Select(driver.find_element_by_name("reason"))
select_box.select_by_visible_text("Sold Elsewhere")
time.sleep(3)
driver.find_element_by_xpath("//*[@type='submit']").click()
except NoSuchElementException:
print("Something went wrong in clearWardrobe()")
traceback.print_exc()
Here is the page with dropdown - I want to select sold elsewhere
And here is the error message:
Something went wrong in clearWardrobe()
Traceback (most recent call last):
File "/Users/thomas.mclaughlin/Documents/GitHub/WardrobeWizard2/scripts/core.py", line 110, in clear_wardrobe
select_box = Select(driver.find_element_by_name("reason"))
File "/Users/thomas.mclaughlin/Library/Python/3.8/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 496, in find_element_by_name
return self.find_element(by=By.NAME, value=name)
File "/Users/thomas.mclaughlin/Library/Python/3.8/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "/Users/thomas.mclaughlin/Library/Python/3.8/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Users/thomas.mclaughlin/Library/Python/3.8/lib/python/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="reason"]"}
(Session info: chrome=89.0.4389.90)