Trying to interact with HTML page elements, but none of them are found

2024/9/22 7:23:49

I'm trying to scrape a webpage using Selenium, but when I try to pass the XPath of a button, I get an error saying that this element does not exist. I tried with another website, and it worked perfectly. I also tried using Puppeteer, but encountered the same problem. When I do $('.selector') for the button I'm trying to click in the page console, it returns an object x.fn.init [prevObject: x.fn.init(1)]. I don't know how to use this to interact with the element itself, but I believe the issue revolves around this.

from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ECdriver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://senamhi.gob.bo/index.php/sysparametros')
open_window_elem = driver.find_element("xpath", '//*[@id="myModal"]/div/div/div')
action = ActionChains(driver)
action.move_by_offset(500, 200)    
action.click()
action.perform()
y_coordinate = open_window_elem.location["y"]
x_coordinate = open_window_elem.location["x"]
action = ActionChains(driver)
action.move_by_offset(x_coordinate, y_coordinate)
action.click()
action.perform()
sleep(20)
driver.find_element('xpath', '/html/body/app-root/app-public-template/app-public-base/app-public-stations-info-export/div/div/div/div[2]/button').click()

The part of clicking somewhere on the screen is working, as when I enter the page, there appears to be a pop-up that requires clicking somewhere to dismiss. Then, a screen with a button comes up that I'm not able to access.

Answer

As you can see in HTML the element that you want to click is inside object element.

Before interacting with any element inside object or iframe you need to instruct selenium to switch to that object, interact with the element that you want to interact with, and then switch back to the default context.

driver.switch_to.frame(driver.find_element("xpath", "//object"))driver.find_element('xpath', '/html/body/app-root/app-public-template/app-public-base/app-public-stations-info-export/div/div/div/div[2]/button').click()driver.switch_to.default_content()
https://en.xdnf.cn/q/119085.html

Related Q&A

Duplicating an XML element and adding it to a specific position in XML file using python

I have a xml file in which content looks like this: xml_content_to_search = <Document ProviderID="TD" DecimalMarker="comma" Website="https://erc-viewer.sap.com/"> &l…

How do I fix this Gets server error, which is causing display issues?

The list in the left column of ontariocourts311.ca, along with the body of the page under the image intermittently fail to display (which is fixed by refreshing the page). Im a Noob, and have tried var…

Installing Scipy for Windows

I am trying to install Scipy on my computer. I did it by using the command pip install Scipy. (pip & numpy are up-to-date and I am using Python 3.6) I also tried it with Pycharm, but it didnt worke…

Python Opencv, dont put circle on the video

I wrote the following script with OpenCVimport cv2 import numpy as npcap = cv2.VideoCapture(0) ix, iy = -1, -1def draw_circle(event, x, y, flags, param):global ixglobal iyix,iy = x,yif event == cv2.EVE…

List coordinates between a set of coordinates

This should be fairly easy, but Im getting a headache from trying to figure it out. I want to list all the coordinates between two points. Like so:1: (1,1) 2: (1,3) In between: (1,2)Or1: (1,1) 2: (5,1)…

NA values in column is not NaN Pandas Python [duplicate]

This question already has answers here:Prevent pandas from interpreting NA as NaN in a string(7 answers)Closed 2 years ago.I got a CSV File. I got a column Product. One of the products in it, called NA…

How to fix pandas column data

Workflow is :Read CSV file using Pythons pandas library and get Variation Column Variation Column data isVariation ---------- Color Family : Black, Size:Int:L Color Family : Blue, Size:Int:M Color Fam…

Connect to Oracle Database and export data as CSV using Python

I want to connect oracle database to python and using select statement whatever result i will get, I want that result to be exported as csv file in sftp location. I know we can connect oracle with pyth…

Pandas data frame: convert Int column into binary in python

I have dataframe eg. like below Event[EVENT_ID] = [ 4162, 4161, 4160, 4159,4158, 4157, 4156, 4155, 4154]need to convert each row word to binary. Event[b]=bin(Event[EVENT_ID]) doesnt work TypeError: can…

I have an issue : Reading Multiple Text files using Multi-Threading by python

Hello Friends, I hope someone check my code and helping me on this issue. I want to read from multiple text files (at least 4) sequentially and print their content on the screenFirst time not using Thr…