I try the code
JavaScript
x
2
1
allSpanDate = self.driver.find_element_by_xpath("//span[text()='08/28']").click()
2
but only first element been clicked
so I edit like this but won’t work
JavaScript
1
4
1
allSpanDate = self.driver.find_element_by_xpath("//span[text()='08/28']")
2
for spanDate in allSpanDate:
3
spanDate.click()
4
website is
http://211.21.63.217:81/ticket_online.aspx
How to click all of the span text is 08/28 ?
JavaScript
1
18
18
1
from selenium import webdriver
2
3
class CenturyasiaxinbeiSpider(scrapy.Spider):
4
name = 'CenturyasiaXinbei'
5
allowed_domains = ['www.centuryasia.com.tw', '211.21.63.217:81']
6
start_urls = ['http://211.21.63.217:81/ticket_online.aspx']
7
8
def __init__(self):
9
print('__init__')
10
self.driver = webdriver.Chrome('/Users/motogod19/chromedriver')
11
self.driver.get('http://211.21.63.217:81/ticket_online.aspx')
12
13
def parse(self, response):
14
allSpanDate = self.driver.find_element_by_xpath("//span[text()='08/28']")
15
for spanDate in allSpanDate:
16
spanDate.click()
17
time.sleep(10)
18
Advertisement
Answer
See, when you did this :
JavaScript
1
4
1
allSpanDate = self.driver.find_element_by_xpath("//span[text()='08/28']")
2
for spanDate in allSpanDate:
3
spanDate.click()
4
you must have got web element is not iterabel error.
that is due to you are using find_element
, try to use find_elements
.
also, I tried the below code in my local,
JavaScript
1
6
1
allSpanDate = driver.find_elements_by_xpath("//span[text()='08/28']")
2
for spanDate in allSpanDate:
3
ActionChains(driver).move_to_element(spanDate).perform()
4
spanDate.click()
5
time.sleep(1)
6
seems to do the job that you’ve been looking for.
Imports :
JavaScript
1
2
1
from selenium.webdriver.common.action_chains import ActionChains
2