0

I'm trying to execute a simple java script command at selenium using python for scroll a part of a web page.

Here's the code:

command_js = 'document.querySelector(' + "'" + 'css_div_example[css_example="this is just a example for css selector"]' + "').scroll(0, 10000)"
#string joined "document.querySelector('css_div_example[css_example="this is just a example for css selector"]').scroll(0, 10000)"
driver.execute_script(command_js)

Picture:

Picture of scroll bar

OBS.:

  • I tried to execute directly from Firefox console and it worked very well.
  • Selenium does not return any error, just not execute it.
  • I tried to WebDriverWait with EC and time.sleep().
  • I am using python 3+ and PyCharm IDE, Firefox webdrivers...

Anyone can help me?

7
  • Can't you just tell selenium to select something down on that div? Commented Oct 12, 2021 at 0:09
  • Contents of the div just appears if scroll down the bar :/ >pt-br: Então, os elementos da div só aparecem quando scrolla a barra, até consigo pegar os primeiros elementos, mas nem sempre vai ser o que preciso... Commented Oct 12, 2021 at 0:52
  • You're switching around quotes there... not sure of syntax for python, but it doesn't look right. You might need escape character... check here: stackoverflow.com/questions/9050355/… Commented Oct 12, 2021 at 20:56
  • You dont need to see the element to select it. You can use: driver.find_element_by_xpath() Commented Oct 14, 2021 at 1:30
  • Podemos ir de ptbr se preferir. Você clica com o botão direito no elemento que quer que o selenium selecione e escolha "inspecionar". Depois clica na parte do código que tem o elemento e escolha: "copy > copy Xpath". Você vai copiar algo semelhante à: //*[@id="description"]/div/table/tbody/tr[1]/th e colar dentro do "find_element_by_xpath()" no seu código. Dá para usar outros elementos de css e dom para selecionar. Commented Oct 14, 2021 at 1:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.