[英]Python Selenium find element by xpath and click doesn't seem to work
我發現有關此主題的問題很少,但是不幸的是,這並沒有幫助我。
我的代碼如下
def gopro(url):
driver = webdriver.Chrome() ##PhantomJS() <- that didnt work either
driver.get(url)
time.sleep(4)
driver.implicitly_wait(5)
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
driver.find_element_by_xpath('//*[@id="gpn-header"]/div[2]/div/div/div[2]/div/div[2]/div[2]/div/select/option[285]').click()
time.sleep(2)
driver.navigate().refresh()
obj = soup.find('h1', {'class':'price-sales notranslate'})
print(obj)
print(gopro('https://shop.gopro.com/Marketing/cameras/hero5-black/CHDHX-502-master.html'))
我也使用過Chromebrowser,這對我想要在網站上進行的操作都沒有幫助,但是我必須更改貨幣(我需要4種貨幣(USD,EUR,GBP和NOK的貨幣)來更改gopro的價格。它位於下拉菜單下upd:為了清楚起見,發布了屏幕截圖,例如,我希望右上角下拉菜單中的語言/貨幣從歐元更改為GBP
我想,您正在嘗試將位置值更改為英國(GB),英語並采用其價格值。
def gopro(url):
driver = webdriver.Chrome() ##PhantomJS() <- that didnt work either
driver.get(url)
time.sleep(4)
driver.implicitly_wait(5)
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
driver.find_element_by_css_selector('.gpn-locale-select-current-country-text').click()
Select(driver.find_element_by_css_selector('.gpn-locale-select-selector')).select_by_visible_text('United Kingdom (GB), English')
time.sleep(2)
driver.navigate().refresh()
obj = soup.find('h1', {'class':'price-sales notranslate'})
print(obj)
print(gopro('https://shop.gopro.com/Marketing/cameras/hero5-black/CHDHX-502-master.html'))
在這里,我嘗試單擊下拉列表並選擇值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.