2017-12-24 28 views
0

私はカートアイテムを掻き集め、ショッピングウェブサイトのそれぞれの価格を取得しようとしています

これまでのところ、これは私のコードですが、エラーが発生しています。私はのために、それぞれのユーザ名とパスワード([email protected]、パリ@日没)を使用すること自由に感じなさい、私は

from selenium import webdriver 
chrome_path =r"C:\Users\aq4'july\Desktop\chromedriver.exe" 
driver = webdriver.Chrome() 
driver.get("https://www.myntra.com/") 

#User Login 
driver.find_element_by_xpath("""//*[@id="desktop-header-cnt"]/div[2]/div[2]/div/div[2]/div[2]/div[2]/a[2]""") 

適切なXPathを取得していないです、私は取得していますエラーが

Traceback (most recent call last): 
    File "<pyshell#16>", line 1, in <module> 
    driver.find_element_by_xpath("""//*[@id="desktop-header-cnt"]/div[2]/div[2]/div/div[2]/div[2]/div[2]/a[2]""").click() 
    File "C:\Users\aq4'july\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click 
    self._execute(Command.CLICK_ELEMENT) 
    File "C:\Users\aq4'july\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\webelement.py", line 501, in _execute 
    return self._parent.execute(command, params) 
    File "C:\Users\aq4'july\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\webdriver.py", line 311, in execute 
    self.error_handler.check_response(response) 
    File "C:\Users\aq4'july\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\errorhandler.py", line 237, in check_response 
    raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible 
    (Session info: chrome=63.0.3239.84) 
    (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.15063 x86_64) 

だと思いますテスト目的。

注:私はPython 3.6を使用していますが、私は質問をしている間に何か逃したことを強調してください。

+0

この式はよく見え、要素と一致する必要があります。あなたはどんなエラーを出していますか?あなたは[Explicit Wait](http://selenium-python.readthedocs.io/waits.html#explicit-waits)で待ってみましたか? – alecxe

+0

番号。このコードをさらに拡張してみてください。カートのアイテムをリストする方法がわかりません –

+0

は常に問題のフルエラーメッセージ(トレースバック)を貼り付けます(テキストとして、スクリーンショットではありません)。その他の有用な情報があります。 – furas

答えて

1

あなたはカートで直接

driver.get('https://www.myntra.com/checkout/cart') 

に行くことができるあなたの中にログインした後、またはあなたが "バッグ" ボタンをクリックすることができ

item = driver.find_element_by_css_selector('.desktop-cart') 
item.click() 
Firefox()

EDITでテスト

全コード:時々ログインには問題がありますが、sleep()がこの問題を解決しているようです。

from selenium import webdriver 
import time 

LOGIN = '[email protected]' 
PASSWORD = 'PaSwOrD' 

# --- start --- 

chrome_path =r"C:\Users\aq4'july\Desktop\chromedriver.exe" 
driver = webdriver.Chrome() 

#driver = webdriver.Firefox() 

# resize window so all elements are visible 
# and the is no problem to click them 
driver.maximize_window() 
#driver.set_window_size(1920, 1080) 
#driver.execute_script("window.resizeTo(1920,1080)") # doesn't work for me 

# --- main page --- 

#driver.get("https://www.myntra.com/") 

# --- login --- 

driver.get('https://www.myntra.com/login?referer=https://www.myntra.com/') 

time.sleep(1) 

item = driver.find_element_by_css_selector('.login-user-input-email') 
item.send_keys(LOGIN) 

item = driver.find_element_by_css_selector('.login-user-input-password') 
item.send_keys(PASSWORD) 

item = driver.find_element_by_css_selector('.login-login-button') 
item.click() 

time.sleep(1) 

# --- main page --- 

#driver.get("https://www.myntra.com/") 

# --- cart --- 

item = driver.find_element_by_css_selector('.desktop-cart') 
item.click() 

# or 

#driver.get('https://www.myntra.com/checkout/cart') 

リサイズ:How do I resize the window in Chrome and Firefox when testing with Selenium?

スクロール:How can I scroll a web page using selenium webdriver in python?

+0

あなたに尋ねたいだけです。同じコードがクロムでも動くことができます。私たちが 'driver = webdriver.Chrome'を変更した場合、 –

+0

もChrome上で動作するはずです - 私はSeleniumのChrome用のドライバを持っていません。 – furas

+0

あなたは人生の節約者です。 –

1

ブロあなただけのページ ログインに行くとものを行うログインしたい場合は.... は、二重引用符を数える」とエスケープシーケンスん

from selenium import webdriver 
import time 
chrome_path ="chromedriver.exe" 
driver = webdriver.Chrome() 
driver.get("https://www.myntra.com/login") 

time.sleep(2) 
driver.find_element_by_xpath("//*[@id=\"mountRoot\"]/div/div/div/form/fieldset[1]/div[1]/input").send_keys("[email protected]tlook.com") 

driver.find_element_by_xpath("//*[@id=\"mountRoot\"]/div/div/div/form/fieldset[1]/div[2]/input").send_keys("[email protected]") 
driver.find_element_by_xpath("//*[@id=\"mountRoot\"]/div/div/div/form/fieldset[2]/button").click() 

time.sleep(2) 

driver.find_element_by_xpath("//*[@id=\"desktop-header-cnt\"]/div[2]/div[2]/a").click() 
time.sleep(2) 
print (driver.find_element_by_xpath("//*[@id=\"prod-item-1514127198\"]/div[2]/div[4]/div/div").text) 

time.sleep(10) 
driver.quit() 

ここにエラーがあります: 3つの二重引用符と「desktop-header-cnt」二重引用符は完全な文字列を分割しています。 driver.find_element_by_xpath( "" * [@ id = "desktop-header-cnt"]/div [2]/div/div [2]/div [2]/a [2] "" ")

+0

非常によく@ zxcV32ありがとう –