0

I'm hoping someone can help me understand a bit better so the site I've been referencing up to this point is https://selenium-python.readthedocs.io/locating-elements.html#locating-elements-by-css-selectors

This is the code (It does work)


#https://www.softwaretestinghelp.com/selenium-python-tutorial/#Configuration_Of_Selenium_In_PyCharm
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By


serv = Service(r"C:\Users\BAtMAn\PycharmProjects\DellUpdate\Drivers\chromedriver.exe")
driver = webdriver.Chrome(service=serv)
driver.get("https://www.dell.com/support")
driver.maximize_window()



def Step1():
    SearchBar = driver.find_element(By.NAME, "entry-main-input-home").send_keys("Test")
    SearchBarClick = driver.find_element(By.ID,"txtSearchEs").click()
Step1()


def Popup():
    if driver.find_element(By.ID, "sec-overlay"):
        time.sleep(30.5)
        SearchBarClick = driver.find_element(By.ID, "txtSearchEs").click()
        time.sleep(5)
Popup()


def FeedBack():
    if driver.find_element(By.CSS_SELECTOR, ('<button id="noButtonIPDell" class="noButton buttons" aria-label="No, thanks">No, thanks</button>)'):
        driver.find_element(By.ID, "button id#noButtonIPDell").click()
FeedBack()

def Drivers():
    if FeedBack() == False:
        driver.find_element(By.ID, "drivers").click()
Drivers()

My issue is I went through a bunch of ID and Class_NAMEs before finding one that works and I'm wondering if it's I just don't understand what I'm reading yet. Below is a list of the class_name and ID's I attempted but driver.find_element didn't locate anything.

CLASS_NAME, ""): custom-Aka-popup-body-area aka-popup-text-center aka-popup-margin-bottom24 custom-Aka-popup-icon

ID es-alert-notice-duotone sec-overlay

Image of the inspected element

Okay so what I was inspecting was the 30 second delay popup that I kept getting from dell.com/support The pop up only seems to appear when running the code not when I manually pull everything up.

Dell FeedBAck (No Button)

(Most current version 8/24 3pm gmt-4) Error(does not click the "Find Drivers drop down")

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//iframe[@title='Dell Survey']"}


# https://www.softwaretestinghelp.com/selenium-python-tutorial/#Configuration_Of_Selenium_In_PyCharm
"""
Pip Installs:
Selenium
"""
import pyautogui
import time
import subprocess
import pyperclip
import re
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By


serv = Service(r"C:\Users\rcowart\Desktop\Robert\Pycharm\DellUpdate - selenium\Driver\chromedriver.exe")
driver = webdriver.Chrome(service=serv)
driver.get("https://www.dell.com/support")
driver.maximize_window()

def SerialNumber():
    SerialNumber = 'wmic bios get serialnumber'
    result = subprocess.getoutput(SerialNumber)
    SerialResult = (result.strip("SerialNumber"))
    print(re.sub("[^a-zA-Z0-9]+", "", SerialResult))
    pyperclip.copy(re.sub("[^a-zA-Z0-9]+", "", SerialResult))
SerialNumber()


def Step1():
    SearchBar = driver.find_element(By.NAME, "entry-main-input-home").send_keys("3Q84KQ2")
    SearchBarClick = driver.find_element(By.ID,"txtSearchEs").click()
    print("Locating SerialNumber")
Step1()


def Popup():
#30 second popup
    if driver.find_element(By.ID, "sec-overlay"):
        time.sleep(30.5)
        driver.find_element(By.ID, "txtSearchEs").click()
        print("Searching: ")
    else:driver.find_element(By.ID,"txtSearchEs").click()
    time.sleep(3)
Popup()

def DriversAndDownloads():
#refresh bypasses the FeedBack not being found
    pyautogui.press("f5")
    if driver.find_element(By.ID, "drivers"):
        driver.find_element(By.ID, "drivers").click()
        print("Successfully Located DriversAndDownloads")
    else:
        pyautogui.press("f5")
        driver.find_element(By.ID, "drivers").click()
        print("Refreshing page!")

def FeedBack():
#popup asking for feedback
    if driver.find_elements(By.ID, "noButtonIPDell"):
        driver.find_element(By.ID, "noButtonIPDell").click()
        print("Sucessfully Located FeedBack: ID")
    else:
#sleep gives DriversAndDownloads time to refresh/find element without the popup covering it
        print("Unable to locate FeedBack!")
        pyautogui.press('f5')
        time.sleep(3)
        DriversAndDownloads()
FeedBack()


def FindDrivers():
#Drop down
    if driver.find_element(By.XPATH, "//iframe[@title='Dell Survey']"):
        driver.find_element(By.XPATH, "//iframe[@title='Dell Survey']").click()
        print("Successfully located FindDrivers: iframe: Dell Survey")
    elif  driver.switch_to.frame("iframeSurvey"):
        driver.find_element(By.ID, "iframeSurvey").click()
        print("Successfully located FindDrivers: iframeSurvey")
    else:
        print("Unable to locate FindDrivers")
FindDrivers()
bad_coder
  • 11,289
  • 20
  • 44
  • 72
  • Having issues still trying to get ID to work on next steps. Any assistance to figure this out is appreciated. –  Aug 20 '22 at 20:29
  • This sounds like an [X-Y problem](http://xyproblem.info/). Instead of asking for help with your solution to the problem, edit your question and ask about the actual problem. What are you trying to do? – undetected Selenium Aug 20 '22 at 20:40
  • @undetectedSelenium I'm trying to inspect the element on a few webpages. Currently I've created a function to check if a pop up .. pops up and if so click no. so (in chrome) the popup up I right click the "no" box and inspect, it returns **** I tried using a few options but ***driver.find_element(By.CSS_SELECTOR, (')')** and ** driver.find_element(By.ID, "button id#noButtonIPDell")** –  Aug 20 '22 at 21:02
  • Somehow I'm unable to repro the **No, thanks** button. Update the question with the manual steps. – undetected Selenium Aug 20 '22 at 21:08
  • @undetectedSelenium It requires you to use an actual dell serial number (doesn't pop up every time but majority of time) I'll include a image of (I'm assuming ) Html –  Aug 21 '22 at 01:37

1 Answers1

0

If you look closely, the "No, Thanks" button is inside an iframe. So if you want to do any action on the elements inside a frame, you would first need to switch to that frame and then try to do the required action on the elements.

I don't think there would be an issue with accessing the button through XPath.

iframe

  • If this works I'm going to cry tears of joy. I've spent several days on these few lines of code (all of this was a new topic for me "selenium, inspecting element(s), autopygui, automation, etc") trying to figure out how to get this to work –  Aug 24 '22 at 12:15
  • I'm having trouble getting the code right. the documents I found said I would need to use a switch first since it's an iframe. I've been using the code.. **if driver.switch_to.frame("title=Dell.Survey"): print("Program has located button!")** and **if driver.switch_to.frame("src=about:blank")** and ** if driver.switch_to.frame(id="iframeSurvey")** and **driver.switch_to.frame("//iframe[@src='about:blank']")** and **driver.switch_to.frame(1)** with no luck do you have any suggestions on a document I can reference or how to write the code? –  Aug 24 '22 at 14:38
  • @navi Please try the below: driver.switch_to.frame("iframeSurvey") or try driver.switch_to.frame(driver.find_element(By.XPATH, "//iframe[@title='Dell Survey']")) – Manu Gopinathan Aug 24 '22 at 17:01
  • if driver.switch_to.frame("iframeSurvey"): **returned selenium.common.exceptions.NoSuchFrameException: Message: iframeSurvey** and if driver.find_element((By.XPATH, "//iframe[@title='Dell Survey']")): **returned selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'using' must be a string *** –  Aug 24 '22 at 18:23
  • Can you try using the wait statement, please? from selenium.webdriver.support import expected_conditions as EC WebDriverWait(driver, 10).wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'iframeSurvey'))) – Manu Gopinathan Aug 25 '22 at 04:58
  • Also, you can refer to the documentation here [link] (https://selenium-python.readthedocs.io/) and another question regarding switching to iframe here [link](https://stackoverflow.com/questions/44834358/switch-to-an-iframe-through-selenium-and-python). Even I am new to selenium with python, so my knowledge is limited. But I strongly believe if you can switch to frame, then you should be able to access the element you wish to click. – Manu Gopinathan Aug 25 '22 at 05:07