Correct "find_element_by_xpath" using title in Python/Selenium

Đã hoàn thành Đã đăng vào 2 năm trước Thanh toán khi bàn giao
Đã hoàn thành Thanh toán khi bàn giao

I'm working on a project and it's important that I find the element "Add Cards Against Humanity to cart" using it's title and finding by xpath on store.cardsagainsthumanity.com. I can see that the button is in an iframe, but I am unable to locate it both using the default iframe or by iterating through them all. I will provide the code being used currently, all I need is to figure out what's wrong with the below code (The indentations don't format properly when pasting below). I'm getting "Element not found."

from selenium import webdriver

import time

from [login to view URL] import NoSuchElementException

from [login to view URL] import StaleElementReferenceException

from [login to view URL] import NoSuchFrameException

options = [login to view URL]()

driver = [login to view URL](options=options, executable_path=r'C:\Users\David\Desktop\Python\chromedriver_win32\[login to view URL]')

url = '[login to view URL]'

[login to view URL](url)

xpath = "//*[@title='Add Cards Against Humanity to cart']"

[login to view URL](2)

print('Finding element')

iframes = driver.find_elements_by_xpath("//iframe")

for index, iframe in enumerate(iframes):

print('Searching iframe ' + str(index))

try:

[login to view URL](index)

try:

element = driver.find_element_by_xpath(xpath)

print(element)

except StaleElementReferenceException:

print('Stale element')

except NoSuchElementException:

print('Element not found on iframe index ' + str(index))

except NoSuchFrameException:

print('frame not found')

driver.switch_to.parent_frame()

try:

print('Element found', element)

except:

print('Element not found')

Python Kiến trúc phần mềm Web Scraping Selenium Selenium Webdriver

ID dự án: #30276270

Về dự án

5 đề xuất Dự án từ xa 2 năm trước đang mở

Được trao cho:

amrkhaled32

Hi, I am Expert in python scraping, I got a great experience with modules of python like bs4, selenium, mechanize, requests, pygame and much more I did many selenium projects like site monitoring, surveys voter a Thêm

$20 USD trong 1 ngày
(1 Nhận xét)
2.5

5 freelancer chào giá trung bình$22 cho công việc này

demydkasilov

Hi, I just read your job details and it is clear to me. Well, as a python developer, I can do automation, scripting and web scraping with python and some libraries like scrapy, selenium, beautifulsoup, etc and export i Thêm

$30 USD trong 7 ngày
(11 Nhận xét)
4.4
potential5656

I think you need to use "FULL XPATH" instead of just XPATH . If you have any trouble figuring it out message me.

$10 USD trong 1 ngày
(3 Nhận xét)
2.7
teresed85

Hi Dear Client. Web scraping is my exactly skill and I CAN SHOW MY WEB SCRAP PROJECT right now. Please let's meet each other first. I have my scraping project by Python framework and it is running now too. Regards.

$20 USD trong 2 ngày
(1 Nhận xét)
0.6