0

I'm trying to use Selenium to get text elements from websites using Node.

As an example, I am using the URL: https://www.ebuyer.com/874785-exdisplay-gigabyte-geforce-rtx-2080-ti-gaming-oc-11gb-graphics-card-ebr2-gv-n208tgaming-oc-11gc and the XPath /html/body/section/div[1]/div[3]/div[1]/div[3]/form/button

I can see in an XPaath selector plugin that it results in "Add to Basket", however the below code logs a blank string. Any idea what I'm doing wrong?

I've tried it with a different element on the page which works, so I'm assuming because its a button?

const selenium = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const chromedriver = require('chromedriver');

chrome.setDefaultService(new chrome.ServiceBuilder(chromedriver.path).build());
const driver = new selenium.Builder()
  .withCapabilities(selenium.Capabilities.chrome())
  .build();

await driver.get(url);
await delay(1000);
const value = await driver.findElement(web.By.xpath(xPath)).getText();
console.log(value)

1 Answer 1

1

Use the following xpath to identify the button.

//div[@class='purchase-info']//input[@value='Add to Basket']

Update:

const value = await driver.findElement(web.By.xpath("//div[@class='purchase-info']//input[@value='Add to Basket']")).getAttribute("value");
console.log(value)
Sign up to request clarification or add additional context in comments.

3 Comments

I still have the same issue. It succeeds the query, but the value is empty
@K20GH: To get the value getText() won't work here you have to use getAttribute("value")
@K20GH : Please check the updated answer and let me know the status?

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.