I am having trouble with selecting an element from a JavaScript webpage using Python's scrapy and Selenium

I am in the process of developing an application to collect data. My tools of choice are Python 2.7 with Scrapy and Selenium on Windows 10. I have successfully implemented this on a few web pages before, however, I am facing an issue with selecting or clicking on a button from the following website.

The problem lies in not being able to click on the button labeled "Search Permits/Complaints".

I have utilized Chrome dev tools to inspect the XPaths, but to no avail.

Here is the relevant code snippet:

import scrapy
from selenium import webdriver

class PermitsSpider(scrapy.Spider):
  name = "atlanta"
  url = "https://aca3.accela.com/Atlanta_Ga/Default.aspx"

  start_urls = ['https://aca3.accela.com/Atlanta_Ga/Default.aspx',]

  def __init__(self):
    self.driver = webdriver.Chrome()
    self.driver.implicitly_wait(20)

  def parse(self, response):
    self.driver.get(self.url)

    time.sleep(15)
    search_button = self.driver.find_element_by_xpath('//*[@id="ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl"]')
    search_button.click()

Executing this code results in the following error message:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*@id="ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl"]"}

Despite adding various sleeps and waits, I have failed to ensure that the page is completely loaded before attempting selection. I have tried other methods for selecting the element like Link Text, without success. It's puzzling why this approach works on some pages and not on others. The WebDriver does launch the page during execution, appearing fully loaded on my screen.

Any assistance on resolving this issue would be highly appreciated. Thank you...

Answer №1

A target link is found within an iframe, requiring a switch to that frame in order to interact with embedded elements:

self.driver.switch_to_frame('ACAFrame')
search_button = self.driver.find_element_by_xpath('//*[@id="ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl"]')

After handling the elements, it may be necessary to switch back using

driver.switch_to_default_content()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A JavaScript technique for combining multiple arrays of objects based on a shared key

I am encountering issues with merging two or more arrays as per my desired outcome. I have two arrays named arrCustomer and arrCustomerDetails. They both contain CustomerID as a key, however, I aim to merge all values from arrCustomerDetails while incorpo ...

Using AngularJS $resource to implement complex service calls

Yesterday, I began my journey with angularjs and found myself at this particular section of the tutorial that demonstrates the usage of $resource to access data from services. In my ASP.Net MVC setup, I encountered a slight hiccup due to the difference in ...

Ways to utilize the <p> tag within the res.write() function

This code snippet is used to display the response of an API request, and I wanted to split my two res.write() parts into separate sections. I attempted using a paragraph tag, but Visual Studio is having some issues :) app.post("/", function(req, res) { ...

Keep the footer at the bottom of the screen without needing to define a 100vh in Material UI

In the process of developing my react app with MUI framework, I encountered various challenges in creating a sticky footer at the bottom of my screen. After exploring different solutions, one approach that I found most satisfactory is as follows: export de ...

Loading an array in batches using javascript

Possible Duplicate: Wait until all jquery ajax request are done? I am faced with the task of loading elements from an array via AJAX using jQuery. I have successfully implemented the logic for loading each element, but now I need to load them in batch ...

Utilize html5 to drag and drop numerous items effortlessly

Recently, I created a basic HTML5 drag and drop feature using JavaScript. However, I encountered an issue. function allowDrop(ev) { ev.preventDefault(); } function drag(ev) { ev.dataTransfer.setData("text", ev.target.id); } function drop(ev) { ...

I successfully implemented the MongoDB connection in my Node.js application, however, it is unfortunately experiencing issues when tested with JMeter

I attempted to establish a connection between JMeter and MongoDB using JavaScript as the scripting language, but encountered failures. The same code worked successfully in Node JS, however, it fails when implemented in JMeter. var mongo = require('m ...

The animation function occasionally halts unexpectedly at a varying position

I am facing an issue with an animation function that I have created to animate a list of images. The function takes in parameters such as frames per second, the stopping point, and the list element containing all the images. However, the animation stops un ...

Rate variable input

After creating my custom function to fetch data from an API in order to change the user's pace, I defined the changePace function with a parameter named "pace". This parameter will be determined based on the user's selection of one of four paces: ...

Difficulty Parsing Date within XLSX File Using SheetJs

When attempting to read an XLSX file using the sheetjs node-module, I encountered a problem with dates in one of the columns. The original data in the file is formatted as '2/17/2020', but after parsing it through xlsx, the format changes to &apo ...

Is there a way to use Selenium to upload a randomly generated file?

Instead of choosing a certain file as shown in the example, I am interested in uploading a random file or selecting the first file from the file explorer. How can I achieve this? selected_file = "/home/you/file.doc" file_input_field = driver.fi ...

Executing numerous Ajax requests within a single Rails view

Two ajax requests are being used on a single page, one showcasing a date and the other displaying a calendar. The first request updates the date upon clicking a date on the calendar. The second request allows for switching between months on the calendar. ...

Display a span element using jQuery datatable to indicate that the update operation was

I have implemented inline editing using jQuery Datatables. Currently, I am trying to display a green checkmark when a record gets updated. Below is the ajax call that populates the table: $.ajax({ url: 'api/massEditorSummary.php', type: &ap ...

What steps should be taken to incorporate a user input space similar to the one found in the Wordpress new post section

I am looking to incorporate a user input section on my website similar to the one found in WordPress for creating new posts. I would like this area to have all of the same tools available, such as adding hyperlinks, bolding text, and uploading images. Ca ...

Error in Taiwlind CSS: Styles are not loading in production environment but are working fine in development environment. This issue is encountered while using Next.js in

After reading various blog posts online, I put together this code snippet. The confusion arises from blogs using autoprefixer while others use postcss-preset-env. In my setup, I have added tailwindcss as a development dependency and properly imported the ...

What should you do when the server is taking a while to respond?

I am in the process of creating a webpage that involves interactions between users, and I could use some guidance. Let's consider this hypothetical scenario: Client A visits a 'public' webpage and clicks a button. Client A then waits for a ...

Discovering the color of a locator (Button/Label) through a CSS locator in Selenium: What's the method?

I have a set of automation scripts in place that handle the downloading and saving of files from a server. These scripts also involve moving the downloaded files from the downloads folder to a user-specific location. When this process is complete, the co ...

Is there a way to resolve the issue of not being able to include screenshots in extent reports?

@AfterMethod public void captureTestResult(ITestResult result) throws Exception{ if(result.getStatus() == ITestResult.FAILURE) { extentLogger.log(Status.FAIL, MarkupHelper.createLabel(result.getThrowable() + " - Test Case Fail ...

Enhance dynamically generated HTML using jQuery Mobile

Using jQuery Mobile version 1.2.0 I am dynamically generating HTML using JavaScript ($(selector).html(content)), adding it to the DOM, and then displaying it ($.mobile.changePage()). After that, I make an AJAX call, retrieve some data, and re-generate th ...

Speed up - Handle alias resolution with module federation

Currently import federation from '@originjs/vite-plugin-federation'; import react from '@vitejs/plugin-react-swc'; import dns from 'dns'; import path from 'path'; import { visualizer } from 'rollup-plugin-visual ...