2

I am using Selenium and Python to create a script for automating end-user workflow in Internet Explorer (has to be IE). When using find_element_by_id, or find_element_by_class_name, I am receiving a NoSuchElementException error.

Can you help me understand why my script is not able to find the id or name for the element "servProvCode"? I have attached screenshots to provide more detail. Thank you!

An error is returned against line 23:

selenium.common.exceptions.NoSuchElementException: Message: Unable to find element with css selector == [id="submit"]

PYTHON SCRIPT:

1 import time
2 from selenium import webdriver
3 from selenium.webdriver.common.by import By
4 from selenium.webdriver.common.keys import Keys
5 from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
6
7 #create capabilities
8 capabilities = DesiredCapabilities.INTERNETEXPLORER
9
10 #delete platform and version keys
11 capabilities.pop("platform", None)
12 capabilities.pop("version", None)
13
14 #start an instance of IE
15 driver = webdriver.Ie(executable_path="C:\\LocalDev\\IEDriverServer.exe", capabilities=capabilities)
16
17 #open Accela login page
18 driver.get("https://pwms-avdev.co.arapahoe.co.us/security/hostSignon.do?signOff=true")
19 time.sleep(2)
20
21 #enter Agency
22 agency = driver.find_element_by_id("servProvCode")
23 agency.send_keys('test', Keys.ENTER)
24 time.sleep(2)
25[enter image description here][1]
26 #enter Username
Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
JohnnieK
  • 23
  • 4
  • I don't see screenshots attached. could you try uploading again? HTML directly posting into the question would be a better choice. – Naveen Kumar R B Jul 27 '18 at 05:53
  • The file attachment process was not straight forward. I thought I had attached images, my apologies. Here is a link to dropbox where there are 2 screen shots. https://www.dropbox.com/sh/4i3bix4aybbmc96/AACXhqGpFF7DNx5deTDl0V7ra?dl=0 – JohnnieK Jul 30 '18 at 14:42
  • I don't see any issue in the locator. I could smell this may be due to the element inside a frame. In the screenshots attached, it is not clearly visible whether the element is inside the frame. if yes, please do as mentioned here https://stackoverflow.com/a/40759300/2575259 – Naveen Kumar R B Jul 30 '18 at 15:01
  • Thank you!, I will review that article and respond with results. – JohnnieK Jul 30 '18 at 15:33
  • It appears there is only one iFrame in the DOM. I have uploaded a new image to the dropbox folder called DOM.png that shows the full stack. https://www.dropbox.com/sh/4i3bix4aybbmc96/AACXhqGpFF7DNx5deTDl0V7ra?dl=0 – JohnnieK Jul 30 '18 at 15:47
  • the elements are inside the frame. you need to first switch to the frame before finding the servProvCode element. just add the following line `driver.switch_to_frame(0)` (i guess index starts from 0, otherwise try 1) – Naveen Kumar R B Jul 31 '18 at 05:29
  • 1
    Thank you for your help Naveen! adding the "driver.switch_to.frame()" line helped fix the issue I was having. – JohnnieK Jul 31 '18 at 19:27

1 Answers1

0

Switching to the frame before finding element solved the issue.

driver.switch_to_frame(0)
agency = driver.find_element_by_id("servProvCode")

References:

in selenium web driver how to choose the correct iframe

Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65